mirror of https://github.com/python/cpython
gh-89474: Improve Semaphore/BoundedSemaphore.release() for multiple thread waiting (GH-92447)
This commit is contained in:
parent
8efda1e7c6
commit
c826867b7c
|
@ -481,8 +481,7 @@ class Semaphore:
|
||||||
raise ValueError('n must be one or more')
|
raise ValueError('n must be one or more')
|
||||||
with self._cond:
|
with self._cond:
|
||||||
self._value += n
|
self._value += n
|
||||||
for i in range(n):
|
self._cond.notify(n)
|
||||||
self._cond.notify()
|
|
||||||
|
|
||||||
def __exit__(self, t, v, tb):
|
def __exit__(self, t, v, tb):
|
||||||
self.release()
|
self.release()
|
||||||
|
@ -506,7 +505,7 @@ class BoundedSemaphore(Semaphore):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, value=1):
|
def __init__(self, value=1):
|
||||||
Semaphore.__init__(self, value)
|
super().__init__(value)
|
||||||
self._initial_value = value
|
self._initial_value = value
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -530,8 +529,7 @@ class BoundedSemaphore(Semaphore):
|
||||||
if self._value + n > self._initial_value:
|
if self._value + n > self._initial_value:
|
||||||
raise ValueError("Semaphore released too many times")
|
raise ValueError("Semaphore released too many times")
|
||||||
self._value += n
|
self._value += n
|
||||||
for i in range(n):
|
self._cond.notify(n)
|
||||||
self._cond.notify()
|
|
||||||
|
|
||||||
|
|
||||||
class Event:
|
class Event:
|
||||||
|
|
Loading…
Reference in New Issue