home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 116.lha / SmallTalk / Sources / MTEST.ST < prev    next >
Encoding:
Text File  |  1986-11-20  |  601 b   |  35 lines

  1. *
  2. * tests for multiprocessing system
  3. *
  4. Declare Mtest Test 
  5. Declare Future Object result sem
  6. Instance Mtest test
  7. Class Mtest
  8.     all
  9.         super all.
  10.         'all multiprocessing tests passed' print.
  11. |
  12.     future        | a f |
  13.         a <- List new.
  14.         f <- Future new; eval: [(1 to: 100) do: [:x | nil]. 
  15.             a addLast: 2. 3].
  16.         a addLast: 1.
  17.         a addLast: f value.
  18.         (a asArray = #(1 2 3))
  19.             ifFalse: [ smalltalk error: 'future error'].
  20.         'future test passed' print
  21. ]
  22. Class Future
  23.     new
  24.         sem <- Semaphore new; set: 0
  25. |
  26.     eval: aBlock
  27.         [ result <- aBlock value. sem signal ] fork
  28. |
  29.     value
  30.         sem wait. 
  31.         sem signal.
  32.         ^ result
  33. ]
  34.  
  35.