threading question

Niels Diepeveen niels at endea.demon.nl
Sun May 14 14:15:38 EDT 2000


Ben Wolfson schreef:
>     cond.notify() #so this should wake thread '2'
>     cond.release()#and this should allow it to acquire the condition
>                   #allowing it to break out of the loop.  When it
>                   #calls notify(), nothing should happen, and then
>                   #it should release.  Instead, thread '2' never
>                   #acquires the condition in the first place
>                   #once thread '1' reaches this point.

By the time thread '1' gets here it has already called cond.acquire() 5
times, so calling cond.release() just once isn't actually going to
release anything. Then thread '1' will terminate while still owning the
lock, so thread '2' will have to wait forever.

BTW, don't you think that this is a rather complicated way to emulate
coroutines?

-- 
Niels Diepeveen
Endea automatisering





More information about the Python-list mailing list