mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #13502: threading: Fix a race condition in Event.wait() that made it
return False when the event was set and cleared right after.
This commit is contained in:
parent
b52e7a9a36
commit
ded0348c08
4 changed files with 27 additions and 5 deletions
|
@ -351,6 +351,22 @@ class EventTests(BaseTestCase):
|
|||
for r, dt in results2:
|
||||
self.assertTrue(r)
|
||||
|
||||
def test_set_and_clear(self):
|
||||
# Issue #13502: check that wait() returns true even when the event is
|
||||
# cleared before the waiting thread is woken up.
|
||||
evt = self.eventtype()
|
||||
results = []
|
||||
N = 5
|
||||
def f():
|
||||
results.append(evt.wait(1))
|
||||
b = Bunch(f, N)
|
||||
b.wait_for_started()
|
||||
time.sleep(0.5)
|
||||
evt.set()
|
||||
evt.clear()
|
||||
b.wait_for_finished()
|
||||
self.assertEqual(results, [True] * N)
|
||||
|
||||
|
||||
class ConditionTests(BaseTestCase):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue