Multiple processes using #nextPutAll:

subbukk subbukk at gmail.com
Sat May 26 05:02:34 UTC 2007


On Friday 25 May 2007 10:00 pm, Damien Cassou wrote:
> Hi,
> testUsingNextPutAll
>   "This test should not pass. Unfortunately, I'm not skilled enough in
> processes management to make this test fail. In fact, since
> #nextPutAll: is not protected, numbers should not be sorted the way
> they are at the end.'"
>
>   |queue writingBlock|
>
>   queue := self newQueue.
>   writingBlock := [queue nextPutAll: (1 to: 10000)].
>   writingBlock
>     fork;
>     fork;
>     fork.
>   Processor yield.
>   self assert: (queue next: 10000) asArray = (1 to: 10000) asArray.
Damien,

I notice two issues with your code.
First, If the code in block runs fast, then it is quite possible for one to 
finish its execution before the next one gets scheduled. Interleaving is 
required only if a process hogs the processor for too long. So it is quite 
possible for the array to contain three runs of 1:10000 in proper sequence. 
This is not an error.

Secondly, yielding just lets background processes run, but does not guarantee 
that they have terminated. These processes have to signal the main process 
waiting in the foreground that they are done and then you can proceed to test 
the queue.

Hope this helps .. Subbu






More information about the Squeak-dev mailing list