[squeak-dev] Some gotchas with #terminate and #critical:
Igor Stasenko
siguctua at gmail.com
Thu Apr 30 06:40:17 UTC 2009
Currently i replacing all calls which affect the scheduling to
redirecting them to Processor, i.e. instead:
self primitiveDoSomething
do:
Processor doSomethingWith: self.
This is to ensure, that no code, in rest of classes , except
ProcessorScheduler deals with scheduling directly.
If i change the Semaphore>>wait method in that way, then it breaks the
trick which sitting in #terminate method :
"Figure out if we are terminating the process while waiting in
Semaphore>>critical:
In this case, pop the suspendedContext so that we leave the ensure:
block inside
Semaphore>>critical: without signaling the semaphore."
(inSema == true and:[
suspendedContext method == (Semaphore compiledMethodAt:
#critical:)]) ifTrue:[
suspendedContext := suspendedContext home.
].
What you think is following alternative implementation:
critical: mutuallyExcludedBlock
| blockValue caught |
caught := false.
[
caught := true.
[self wait.] ifCurtailed: [ caught:=false ].
blockValue := mutuallyExcludedBlock value
] ensure: [caught ifTrue: [self signal]].
^blockValue
avoids the need in having tricks in #terminate?
--
Best regards,
Igor Stasenko AKA sig.
More information about the Squeak-dev
mailing list
|