From 7634e1cf9028ed5b21f0a97db45c91d8e8a159a6 Mon Sep 17 00:00:00 2001 From: Tim Peters Date: Tue, 8 Oct 2013 20:55:51 -0500 Subject: Issue 19158: a rare race in BoundedSemaphore could allow .release() too often. --- Lib/threading.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Lib/threading.py') diff --git a/Lib/threading.py b/Lib/threading.py index c98a006231..3d4952b586 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -283,9 +283,11 @@ class BoundedSemaphore(Semaphore): self._initial_value = value def release(self): - if self._value >= self._initial_value: - raise ValueError("Semaphore released too many times") - return Semaphore.release(self) + with self._cond: + if self._value >= self._initial_value: + raise ValueError("Semaphore released too many times") + self._value += 1 + self._cond.notify() class Event: -- cgit v1.2.1