More Delay/Semaphore "fun"

Gary Chambers gazzaguru2 at btinternet.com
Mon Oct 8 14:28:40 UTC 2007


Possibly. Have you tested this?
For the moment, to allow us to move on, we've switched to Semaphores and avaoided nesting.

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org
> [mailto:squeak-dev-bounces at lists.squeakfoundation.org]On Behalf Of Paolo
> Bonzini
> Sent: 08 October 2007 2:54 PM
> To: squeak-dev at lists.squeakfoundation.org
> Subject: Re: More Delay/Semaphore "fun"
> 
> 
> Gary Chambers wrote:
> > Well, we're finding that you fixes are helping a lot (maybe not 
> 100% watertight but much better than without!).
> > 
> > For a more difficult challenge:
> > 
> > Monitor>>critical:
> 
> Not really... It would be more complicated to support *everything* in 
> Monitor.  But if all you want is a recursion-safe mutex, you can inline 
> enter and exit (and the nestingLevel variable is useless now):
> 
> | us |
> us := Processor activeProcess.
> ownerProcess == us
>      ifTrue: [ ^aBlock value ]
>      ifFalse: [
> 	mutex critical: [
> 	    ["When we enter, the mutex is free so ownerProcess is nil.
>                So the unwinding does not mess up anything."
>              ownerProcess := us.
> 	    blockValue := aBlock value ]
> 		ensure: [ ownerProcess := nil ] ] ].
>      ^blockValue
> 
> The complicated stuff is done in Semaphore>>#critical: and Monitor can 
> simply leverage that.
> 
> Alternatively, you could have a primitive to notify a waiter on a 
> semaphore without adding a signal (a no-op if there is no one waiting). 
>     This simplifies everything because the excess signals are always 
> zero!  Then the code would look like this:
> 
> reset := false.
> [ ownerProcess == us ] whileFalse: [
>      semaphore wait.
>      ownerProcess isNil ifTrue: [ownerProcess := us. reset := true]].
> [ blockValue := aBlock value ]
>      ensure: [reset ifTrue: [ownerProcess := nil. semaphore notify]].
> ^blockValue
> 
> Paolo
> 
> 




More information about the Squeak-dev mailing list