[Python-Dev] New PEP: 319

Jack Jansen Jack.Jansen@cwi.nl
Tue, 17 Jun 2003 11:01:38 +0200


Most points have been addressed by Skip and Greg and others already, but
there's one I'd like to elaborate a little on:

On Monday, Jun 16, 2003, at 17:16 Europe/Amsterdam, Michel Pelletier 
wrote:
>> [*] 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.
>
> I belive the reverse, synchronize will reduce user error and 
> deadlocking
> code.  with explicit locks programmers will forget, or become confused,
> with when and how to explicitly lock and unlock.

The problem is if one piece of code has
	synchronise a:
		...
		synchronise b:
			...
and somewhere else you have
	synchronise b:
		...
		synchronise a:
			...

If you use fine-grained locking this is something you always have to be 
aware of.
In C-class languages it requires only discipline (don't call any 
subroutines
outside of your module while holding a lock, basically), in Python you 
can forget it
because every single statement or expression can be calling out all 
over the
place.

Note that this same problem turns up with Greg's "synchronised class" 
idea: if the
language makes locking easy people will overuse it and it will come 
back to bite you
(or, probably, a user of your module).
--
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