All pastes #38172 Raw Edit

Something

public text v1 · immutable
#38172 ·published 2006-01-23 13:45 UTC
rendered paste body
10 timesRepeat: [
       | collection threadCount semaphore safeguard |
       collection := SortedCollection new.

       safeguard := Semaphore forMutualExclusion.

       threadCount := 50.
       semaphore := Semaphore new.
       semaphore signal.

       (1 to: threadCount) do: [:each |
               Transcript show: each asString;cr.
               semaphore signal.
               [1 to: 250000 do: [:x |
                     safeguard critical: [collection add: x; remove: x]]] fork.
               semaphore wait].

       semaphore wait]