Event triggers, smart semaphores?

Michael S. Klein mklein at alumni.caltech.edu
Fri May 28 19:43:49 UTC 1999


> I have found this to be a problem with OO and Semaphores
> in general - there is so much cross-calling of messages it
> is difficult to predict when a locked message will call itself.
> It would be good to have a "smart semaphore" that forced
> outside callers to wait, but let self invoke multiple invocations

VW has a RecursionLock which is basicly a "smart Semaphore" that
knows which Process holds the lock, thereby alowing recursive calls
into the protected sections -- invaluable for thread-safe (I.E. Smalltalk 
Process-safe) code.

I've also found other similar smart mutex's to be usefull.  I had
a TimeZone class which called-out to the OS (Unix) for doing timezone
calculations.  Unfortunately, the Unix libraries have the timezone
global to the OS's process. I had a lock that blocked all entrants who
wanted to do a calculation in a different zone than the zone held by the 
lock.

Generally, I find that simple mutexes around small block's of code
arise from cleaner designs.  Recursion locks are bigger armour-plating
for putting around large pieces of functionality, usually in concert
with general exception handling.

-- Mike klein

mklein at alumni.caltech.edu





More information about the Squeak-dev mailing list