[Python-Dev] New PEP: 319

Jack Jansen Jack.Jansen@cwi.nl
Mon, 16 Jun 2003 11:20:14 +0200


On Monday, Jun 16, 2003, at 09:19 Europe/Amsterdam, Michel Pelletier 
wrote:
> No explicit lock is necessary.  Any object may be synchronized upon
> (except, perhaps, None).  The first time an object is synchronized, a 
> lock
> is invisibly associated with it behind the scenes, you cannot (and 
> should
> not) access this lock.  The lock exists for the life of the object it
> synchronizes.  When a synchronize block is entered, the lock is 
> acquire()d
> and and release()d when the block is exited.

I think this is a bad idea, after pondering it for a while[*]. There 
will always be situations where you want to lock multiple objects, and 
before you know it you'll end up with extra objects that hold no data 
but only a lock. And then it would have been better to design the 
language feature that way in the first place. Explicit is better than 
implicit:-)

[*] I wondered for a while whether locking only a single object would 
maybe steer people away from potentially deadlocking code, but I 
believe it's the other way around: with explicit locks you actually 
have to think of the locks you need, whereas with implicit locks you 
don't, so you write deadlocking code more often.
--
Jack Jansen, <Jack.Jansen@cwi.nl>, http://www.cwi.nl/~jack
If I can't dance I don't want to be part of your revolution -- Emma 
Goldman