Semaphore>>critical: ?

Göran Hultgren gohu at rocketmail.com
Sun Sep 2 16:27:09 UTC 2001


Hi guys!

I am hacking away on a Flow based client/server thingy and needed to use a Semaphore as a mutex.
So I did something like this:

myMutex critical: [ ...code code... ^self ...code code...]

...and oops, got bitten by the fact that the Semaphore does not get signalled when I have a return
in my critical code block! Of course, it was simple to rewrite the code without returns but...

Is there any particular reason (performance etc) that prevents us from changing the implementation
of #critical: to this (thus not missing to signal the Semaphore)?:

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]


The funny thing is that this seems to work EXCEPT for one Unit test I have which seems to "hang"
on the "self signal" part above. Funny enough, if I alt-. it and then just "proceed" it moves on!

Obviously I am missing some piece of the puzzle, right? In any case this should perhaps be
mentioned in the comment to #critical:

regards, Göran

PS. This is in a rather old image pdated to 2915 with JMM's Flow and SUnit 2.7.1. DS

=====
Göran Hultgren, goran.hultgren at bluefish.se
GSM: +46 70 3933950, http://www.bluefish.se
"Department of Redundancy department." -- ThinkGeek

__________________________________________________
Do You Yahoo!?
Get email alerts & NEW webcam video instant messaging with Yahoo! Messenger
http://im.yahoo.com




More information about the Squeak-dev mailing list