[squeak-dev] Re: Some gotchas with #terminate and #critical:

Igor Stasenko siguctua at gmail.com
Thu Apr 30 06:53:24 UTC 2009


2009/4/30 Igor Stasenko <siguctua at gmail.com>:
> 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?
>

the test code:

| result |
result := 0.
[ [  result := 5.
	 [Processor terminateActive] ifCurtailed: [ result := 10 ].
 ] ensure: [ result := 1 -> result ].
] forkAt: Processor highestPriority.
result

returns result == (1->10)

and:

| result sema |
sema := Semaphore new.
result := 0.
([ [  result := 5.
	 [sema wait] ifCurtailed: [ result := 10 ].
 ] ensure: [ result := 1 -> result ].
] forkAt: Processor highestPriority) terminate.
result

returns result == (1->10) as well.

> --
> Best regards,
> Igor Stasenko AKA sig.
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list