[Python-Dev] [Python-checkins] cpython: asyncio: Change bounded semaphore into a subclass, like (original) (raw)
Tim Peters tim.peters at gmail.com
Sun Nov 24 00🔞37 CET 2013
- Previous message: [Python-Dev] can someone create a buildbot slave name & password for me?
- Next message: [Python-Dev] buildbot's are needlessly compiling -O0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
[guido]
http://hg.python.org/cpython/rev/6bee0fdcba39 changeset: 87468:6bee0fdcba39 user: Guido van Rossum <guido at python.org> date: Sat Nov 23 15:09:16 2013 -0800 summary: asyncio: Change bounded semaphore into a subclass, like threading.[Bounded]Semaphore.
files: Lib/asyncio/locks.py | 36 ++++++++-------- Lib/test/testasyncio/testlocks.py | 2 +- 2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/Lib/asyncio/locks.py b/Lib/asyncio/locks.py --- a/Lib/asyncio/locks.py +++ b/Lib/asyncio/locks.py @@ -336,22 +336,15 @@
...
+class BoundedSemaphore(Semaphore): ... + def release(self): + if self.value >= self.boundvalue: + raise ValueError('BoundedSemaphore released too many times') + super().release()
If there's a lock and parallelism involved, this release() implementation is vulnerable to races: any number of threads can see "self._value < self._bound_value" before one of them manages to call the superclass release(), and so self._value can become arbitrarily larger than self._bound_value. I fixed the same bug in threading's similar bounded semaphore class a few weeks ago.
- Previous message: [Python-Dev] can someone create a buildbot slave name & password for me?
- Next message: [Python-Dev] buildbot's are needlessly compiling -O0
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]