#fork and deterministic resumption of the resulting process

Paolo Bonzini bonzini at gnu.org
Fri Feb 8 09:29:58 UTC 2008


>>> Andreas is a great programmer, but the example he posted had a bug in
>>> it and the proposed fix was incorrect.
>>
>> The patch is correct in its Squeak context.
> 
> Unless I've missed some correction to the patch, the patch isn't 
> correct.

Here is code for my issue instead.

| queue stop s |
queue := SharedQueue new.
stop := false.
s := Semaphore new.
[ s signal.
   [ stop ] whileFalse: [ queue nextPut: true. Processor yield ] ] fork.
s wait.
[ (Delay forMilliseconds: 500) wait. stop := true ] fork.
[ stop ] whileFalse: [ queue nextPut: false. Processor yield ].

Without the patch *and with any scheduler that executes same-priority 
processes fairly* the program is ensured to finish.  With the patch, the 
program might not finish.  The two producer processes might ping-pong 
control to each other, and the delay won't even be started.

Paolo



More information about the Squeak-dev mailing list