Message198928
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). |
|
Date |
User |
Action |
Args |
2013-10-04 00:00:16 | tim.peters | set | recipients:
+ tim.peters |
2013-10-04 00:00:16 | tim.peters | set | messageid: <1380844816.11.0.829919053917.issue19158@psf.upfronthosting.co.za> |
2013-10-04 00:00:16 | tim.peters | link | issue19158 messages |
2013-10-04 00:00:15 | tim.peters | create | |
|