This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kristjan.jonsson
Recipients brian.curtin, jyasskin, kristjan.jonsson, pitrou, terry.reedy, tim.golden
Date 2010-08-08.20:27:28
SpamBayes Score 3.970599e-07
Marked as misclassified No
Message-id <1281299250.45.0.498268194338.issue8411@psf.upfronthosting.co.za>
In-reply-to
Content
Thanks for your comments.
The problem with _cond_timed_wait indicates that the timed wait code hadn't been thoroughly tested at the time of submission.

1) The InterlockedDecrement was left in by mistake.  It must be removed
2) The LONG was argument was a vestige from trying to prevent the benign race condition with the _cond_timed_wait.

As for the race condition, it is as follows:
a) Thread A is waiting in _cond_timed_wait(), n_waiting == 1
b) The wait times out and it tries to acquire the lock to decrement n_waiting.  This is a critical lock, because no one is waiting for the semaphore, yet n_waiting == 1
c) Thread B, that has the lock, calls _cond_signal().  It still sees n_waiting == 1 and does a ReleaseSemaphore.  It then also decrements n_waiting, and n_waiting is now 0.  The Semaphore count is now 1
d) Thread A finally gets the lock and decrements n_waiting.  n_waiting is now -1.

n_waiting has thus been decremented twice.  But this is ok, since there was also an extra ReleaseSemaphore call and the semaphore count is now 1.  The upshot of this is that this race condition is benign, and what happens is that the next time someone does _cond_wait(), the semaphore is reduced to 0, n_waiting goes to 0, and the thread passes right through.  Thus, should this event happen, the only upshot of it is that one _cond_wait call will be ineffective.

I'll upload a new patch with better explanation.
History
Date User Action Args
2010-08-08 20:27:30kristjan.jonssonsetrecipients: + kristjan.jonsson, terry.reedy, pitrou, jyasskin, tim.golden, brian.curtin
2010-08-08 20:27:30kristjan.jonssonsetmessageid: <1281299250.45.0.498268194338.issue8411@psf.upfronthosting.co.za>
2010-08-08 20:27:29kristjan.jonssonlinkissue8411 messages
2010-08-08 20:27:28kristjan.jonssoncreate