Movatterモバイル変換
[0]ホーム
[Python-Dev] New PEP: 319
Michel Pelletiermichel@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 variablessimpler, because they would not need to be associated with their own lock,or rather, the lock currently associated with them would not need to beused. Given the example in:http://www.python.org/doc/current/lib/condition-objects.htmlthe psedo-code would become:# Consume one itemsynchronize cv: while not an_item_is_available(): cv.wait() get_an_available_item()# Produce one itemsynchronize cv: make_an_item_available() cv.notify()there is a problem here, however, and I *think* this is the question youare asking. The manual states " The wait() method releases the lock, andthen blocks until it is awakened by a notify() or notifyAll() call for thesame condition variable in another thread. Once awakened, it re-acquiresthe 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 asychronizewould not be used. or, wait() could be changed to do nothing with thelock and simply wait() inside an asynchronize block:# Consume one itemsynchronize cv: while not an_item_is_available(): asynchronize: cv.wait() get_an_available_item()-Michel
[8]ページ先頭