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

Igor Stasenko siguctua at gmail.com
Fri May 1 22:30:38 UTC 2009


With implementation of TerminateProcess exception, i now solved this issue.

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

now works w/o failure in new scheduler.

A code for critical section now looks like:

critical: mutuallyExcludedBlock			
	"Evaluate mutuallyExcludedBlock only if the receiver is not currently in
	the process of running the critical: message. If the receiver is, evaluate
	mutuallyExcludedBlock after the other critical: message is finished."
	| blockValue caught |
	caught := false.
	[
		caught := true.
		[self wait] on: TerminateProcess do: [:ex | caught := ex
abandonedSemaphore ~~ self ].
		blockValue := mutuallyExcludedBlock value
	] ensure: [caught ifTrue: [self signal]].
	^blockValue



2009/4/30 Igor Stasenko <siguctua at gmail.com>:
> 2009/4/30 Andreas Raab <andreas.raab at gmx.de>:
>> 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.
>>
>
> Ok, any ideas how to ensure expected behavior without poking the context stack?
> Because in new scheduler, a #wait implemented differently.
>
>> Cheers,
>>  - Andreas
>>
>>
>
>
>
> --
> Best regards,
> Igor Stasenko AKA sig.
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list