More Delay/Semaphore "fun"
Paolo Bonzini
bonzini at gnu.org
Sun Oct 7 08:24:53 UTC 2007
Andreas Raab wrote:
> Igor Stasenko wrote:
>> On 06/10/2007, Andreas Raab <andreas.raab at gmx.de> wrote:
>>> Igor Stasenko wrote:
>>>> Then the only way is to make it to handle all by VM.
>>> Maybe not quite. Check out http://bugs.squeak.org/view.php?id=6588 to
>>> see if this addresses your problem. It appears to work remarkably well
>>> for me.
>>
>> A bit hacky approach, don't you think?
>
> Without any doubt. But I don't see a quick solution to the problem that
> isn't a bit of a hack. It's not clear what a VM-driven solution looks
> like either btw.
GNU Smalltalk does it like this:
| caught |
^[
[
"The VM will not preempt the process between the two statements.
Note that it is *wrong* to set the variable to true before
obtaining the semaphore, but the exception handler straightens
that. On the other hand, setting the variable to true after the
wait would be wrong if the process was preempted and terminated
after the wait (hence, with `caught' still set to false and the
semaphore obtained)."
caught := true.
self wait ] on: ProcessBeingTerminated do: [ :ex |
ex semaphore isNil ifFalse: [ caught := false ] ].
aBlock value ]
ensure: [caught ifTrue: [self signal] ]
with Process>>#terminate sending a ProcessBeingTerminated notification
before issuing the final "suspend" call. If the process was waiting on
a semaphore (as seen from the suspendingList), that semaphore is stored
into the notification. Seems to work.
Paolo
More information about the Squeak-dev
mailing list
|