[Python-Dev] Pre-PEP: with syntax (was: New syntax threads -- summary wanted)
Bernhard Herzog
bh@intevation.de
10 Feb 2003 15:26:34 +0100
"M.-A. Lemburg" <mal@lemburg.com> writes:
> Bernhard Herzog wrote:
> > "M.-A. Lemburg" <mal@lemburg.com> writes:
> >>The original argument for this was not to save you typing,
> >>it was built on the rather unlikely case where the process
> >>receives a signal or MemoryError causing an exception while
> >>executing the byte codes after calling .acquire() and before
> >>entering the try-block.
> >>
> >>However, that's not hard to deal with either because
> >>all you need to do is place the .acquire() call inside
> >>the try-block and then adding a check whether you have to
> >>release the lock in the finally-clause.
> > That just moves the race condition to a different place. If the acquire
> > call is inside the try block the place of the race condition is between
> > the acquire call and setting a flag or in the finally clause between
> > checking a flag and actually releasing the lock.
>
> Not if the lock object is protected by the global
> interpreter lock which usually is the case if the
> lock object is implemented C.
That's not enough, unfortunately.
In the particular case of locks, the threading.Lock object's release
method must only be called when it's locked (same for the other lock
objects AFAICT). Seems to me that this would require a flag at the
python level and then you have the race condition.
Even worse, the race condition is also in something like
try:
...
finally:
mylock.release()
as the finally clause consists of several byte codes.
Bernhard
--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
MapIt! http://www.mapit.de/