Semaphore>>critical:

Stephan Rudlof sr at evolgo.de
Fri Dec 6 14:31:20 UTC 2002


Stephen Pair wrote:
> This methods reads:
> 
> -----
> 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 |
> 	self wait.
> 	[blockValue _ mutuallyExcludedBlock value]
> 		ensure: [self signal].
> 	^blockValue
> -----
> 
> I've been using the following version for quite some time without any
> trouble:
> 
> -----
> 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."
> 
> 	self wait.
> 	^mutuallyExcludedBlock ensure: [self signal]
> -----
> 
> Is there any reason why my version is not correct?

I don't see any.

Possibly the author hasn't been sure about getting the correct return value
(value of the mutuallyExcludedBlock) from #ensure: ?
But it does in accordance with ANSI, which defines for #ensure: to return
the value of the mutuallyExcludedBlock, so your version looks correct to me.

Any other thoughts out there?


Greetings,

Stephan


> Again it seems to
> work, and it gets much more to the point.
> 
> - Stephen 
> 
> 
> 


-- 
Stephan Rudlof (sr at evolgo.de)
   "Genius doesn't work on an assembly line basis.
    You can't simply say, 'Today I will be brilliant.'"
    -- Kirk, "The Ultimate Computer", stardate 4731.3




More information about the Squeak-dev mailing list