[Python-Dev] New PEP: 319

Michel Pelletier michel@dialnetwork.com
Mon, 16 Jun 2003 03:00:25 -0500 (CDT)


> I'd also like to see how 'asynchronize' works with condition
> variables, which seem to be the most common use for temporarily
> unlocking.

Hmm... I think the 'synchronize' keyword would make condition variables
simpler, because they would not need to be associated with their own lock,
or rather, the lock currently associated with them would not need to be
used.  Given the example in:

http://www.python.org/doc/current/lib/condition-objects.html

the psedo-code would become:

# Consume one item
synchronize cv:
    while not an_item_is_available():
        cv.wait()
    get_an_available_item()

# Produce one item
synchronize cv:
    make_an_item_available()
    cv.notify()

there is a problem here, however, and I *think* this is the question you
are asking.  The manual states " The wait() method releases the lock, and
then blocks until it is awakened by a notify() or notifyAll() call for the
same condition variable in another thread. Once awakened, it re-acquires
the lock and returns. It is also possible to specify a timeout. "

Is the question your asking, How does 'wait()' unlock a hidden lock? 
(FYI, Java does it by making all objects condition variables, wait,
notify, and notifyAll are methods of java.lang.Object)  Perhaps a __x__
method could provide access to the "hidden" lock for wait and asychronize
would not be used.  or, wait() could be changed to do nothing with the
lock and simply wait() inside an asynchronize block:

# Consume one item
synchronize cv:
    while not an_item_is_available():
        asynchronize:
            cv.wait()
    get_an_available_item()

-Michel