[squeak-dev] Re: Example of non-concurrent code :)

Andreas Raab andreas.raab at gmx.de
Sat Oct 16 05:00:57 UTC 2010


On 10/15/2010 9:41 PM, Igor Stasenko wrote:
> Here, the bug:
> first it sends #peekEvent and its not nil.
> Okay, then after some logic voodo, it sends nextEvent, without
> precaution, that it may also answer nil!
>
> So, if some other process get between these two sends (*a*, *b*) and
> fetch/flush all events, a code will fail,

But there is no such code. The method in question is run from within 
Morphic so unless there is a concurrent thread which for some reason 
flushes the event queue[*1], this case simply cannot happen. The shared 
queue used for synchronization here is specifically for synchronizing 
the event queue with the Morphic event loop. It's not for general 
purpose let's-just-dump-all-events-at-random-points-in-time usage.

[*1] I would claim that such code itself buggy. Flushing the event queue 
should be synchronized with Morphic.

Cheers,
   - Andreas

> The fix is simple:
>
> nextEvent := Sensor nextEvent.
> nextEvent ifNotNil: [ trail nextPut: nextEvent third @ nextEvent fourth]
>
> Both Pharo&  Squeak contain this bug. But this method slightly differs
> from each other.
>




More information about the Squeak-dev mailing list