]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-89474: Improve Semaphore/BoundedSemaphore.release() for multiple thread waiting...
authorDong-hee Na <donghee.na@python.org>
Sun, 8 May 2022 13:33:53 +0000 (22:33 +0900)
committerGitHub <noreply@github.com>
Sun, 8 May 2022 13:33:53 +0000 (22:33 +0900)
Lib/threading.py

index 642f93e1eec31ce4d66b6176e78593d7bf7cb232..40edcde11539d65521550f323cd2e81f1d68e382 100644 (file)
@@ -481,8 +481,7 @@ class Semaphore:
             raise ValueError('n must be one or more')
         with self._cond:
             self._value += n
-            for i in range(n):
-                self._cond.notify()
+            self._cond.notify(n)
 
     def __exit__(self, t, v, tb):
         self.release()
@@ -506,7 +505,7 @@ class BoundedSemaphore(Semaphore):
     """
 
     def __init__(self, value=1):
-        Semaphore.__init__(self, value)
+        super().__init__(value)
         self._initial_value = value
 
     def __repr__(self):
@@ -530,8 +529,7 @@ class BoundedSemaphore(Semaphore):
             if self._value + n > self._initial_value:
                 raise ValueError("Semaphore released too many times")
             self._value += n
-            for i in range(n):
-                self._cond.notify()
+            self._cond.notify(n)
 
 
 class Event: