[guido]
> http://hg.python.org/cpython/rev/6bee0fdcba39
> changeset: 87468:6bee0fdcba39
> user: Guido van Rossum <[email protected]>
> 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/test_asyncio/test_locks.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._bound_value:
> + 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.
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com