nil in SuspendedDelays???

Cees De Groot cdegroot at gmail.com
Mon Jan 23 13:39:06 UTC 2006


And here is another funny one. Two colleagues of mine where looking
whether our trouble was related to SortedCollection in combination
with Semaphore (these are the primary objects involved with the
original issue, and we have another couple of bug reports which shows
sorted collections exhibiting funny behavior even though the are
protected by Semaphores).

They whipped this up:

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.

        self assert: collection isEmpty]

This code reliably crashes in the "remove: x" mentioning that the
object is not present in the collection. Which, looking at the code,
is impossible.

Is Semaphore broken? Or are we overlooking something in our test?



More information about the Squeak-dev mailing list