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

Andreas Raab andreas.raab at gmx.de
Thu Apr 30 15:59:37 UTC 2009


Igor Stasenko wrote:
> 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?

It doesn't. For example:

   sema := Semaphore forMutualExclusion.
   p := [sema critical:[]] forkAt: Processor activePriority - 1.
   sema critical:[( Delay forMilliseconds: 100) wait].
   p terminate.
   self assert: sema isSignaled.

Cheers,
   - Andreas



More information about the Squeak-dev mailing list