Atomic operations (was Re: [Python-Dev] Why did Fredrik leave the party?)

Barry A. Warsaw barry@python.org
Thu, 6 Feb 2003 09:11:47 -0500


>>>>> "ESR" == Eric S Raymond <esr@thyrsus.com> writes:

    ESR> I'm going to have to come out against this idea.  I think it
    ESR> violates "explicit is better than implicit", and is
    ESR> perilously close to being mere syntactic sugar.

Except that it's not, because of the lack of atomic acquire-and-enter-try.

You could probably code this specific example like so:

    try:
	lock.acquire()
	dosomething()
    finally:
	try:
	    lock.release()
	except NotLocked:
	    pass

but you still have the problem of ironclad resource release in
other situations, such as the cursor opening scenario (I think) I
posted before.

Brett (I think) suggested that there may be alternatives to a
syntactic approach, e.g. one that prohibits thread switching between
the resource acquisition and the entering of the try.  That might be
interesting to explore, but I worry about deadlock possibilities.

-Barry