Critical sections (was: RE: Lots of concurrency)

Stephen Pair spair at advantive.com
Fri Oct 26 02:36:38 UTC 2001


> > Speaking of critical sections, some dialects of Smalltalk 
> allow you to
> > write:
> > 
> > 	[ balance := balance - 500 ] critical.
> > 
> 
> Well, the semantics of this are pretty awkward in Smalltalk.  
> Also, read some of the recent posts about Java's synchronized 
> keyword -- it might not be as useful in practice as it looks 
> on a small scale.

Seems pretty clear to me, I would assume that this block, and only this
block, is protected.  But, I could see how one might get confused over
it.  I agree that it is probably less useful than one might be inclined
to think, however, it's not completely useless either.  Usually, there
is more than one section of code that you need to protect by a single
mutex, and this wouldn't work for those situations. 
 
> However, the following exists and is convenient in Squeak:
> 
>   aSemaphore critical: [ balance := balance - 500 ]

Of course.

> Anyway, much better than even this is to rephrase your system 
> in terms of message passing, as discussed elsewhere in this 
> thread.  Critical sections are just really tough to work with by hand.

I'd be interested to see how you would do that with this bank account
withdrawal example.  I can think of one potential solution, but I think
it would be more awkward...a case of the cure being worse than the
disease so to speak.

- Stephen





More information about the Squeak-dev mailing list