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 tim.peters
Recipients tim.peters
Date 2013-10-04.00:00:15
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1380844816.11.0.829919053917.issue19158@psf.upfronthosting.co.za>
In-reply-to
Content
I'm sure this flaw exists on more than just the current default branch, but didn't check.

BoundedSemaphore.release() doesn't quite do what it thinks it's doing.  By eyeball, the code obviously suffers from a small timing hole:  multiple threads releasing at the same time can all see "self._value >= self._initial_value" as false before any of them actually releases the semaphore.  So the value of ._value can become arbitrarily higher than ._initial_value.

This is hard to provoke.  The attached patch adds a TESTWAIT Event to BoundedSemaphore so that the new file (unbounded.py) can demonstrate the race reliably.  The patch doesn't fix anything - it's just a way to demonstrate the problem.  At the end, unbounded.py prints

bs._value is 2

That should be "impossible" for a BoundedSemaphore(1).
History
Date User Action Args
2013-10-04 00:00:16tim.peterssetrecipients: + tim.peters
2013-10-04 00:00:16tim.peterssetmessageid: <1380844816.11.0.829919053917.issue19158@psf.upfronthosting.co.za>
2013-10-04 00:00:16tim.peterslinkissue19158 messages
2013-10-04 00:00:15tim.peterscreate