summaryrefslogtreecommitdiffstats
path: root/Lib/test/lock_tests.py
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2019-08-29 08:45:19 (GMT)
committerGitHub <noreply@github.com>2019-08-29 08:45:19 (GMT)
commit35f6301d68bdb0517be284421782d64407dfe72c (patch)
tree2b25b22aa2800545bdcac6bbfe9ab36472e6542a /Lib/test/lock_tests.py
parent0dac68f1e593c11612ed54af9edb865d398f3b05 (diff)
downloadcpython-35f6301d68bdb0517be284421782d64407dfe72c.zip
cpython-35f6301d68bdb0517be284421782d64407dfe72c.tar.gz
cpython-35f6301d68bdb0517be284421782d64407dfe72c.tar.bz2
bpo-10978: Semaphores can release multiple threads at a time (GH-15588)
Diffstat (limited to 'Lib/test/lock_tests.py')
-rw-r--r--Lib/test/lock_tests.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/lock_tests.py b/Lib/test/lock_tests.py
index 23a02e0..8885868 100644
--- a/Lib/test/lock_tests.py
+++ b/Lib/test/lock_tests.py
@@ -663,6 +663,38 @@ class BaseSemaphoreTests(BaseTestCase):
b.wait_for_finished()
self.assertEqual(sem_results, [True] * (6 + 7 + 6 + 1))
+ def test_multirelease(self):
+ sem = self.semtype(7)
+ sem.acquire()
+ results1 = []
+ results2 = []
+ phase_num = 0
+ def f():
+ sem.acquire()
+ results1.append(phase_num)
+ sem.acquire()
+ results2.append(phase_num)
+ b = Bunch(f, 10)
+ b.wait_for_started()
+ while len(results1) + len(results2) < 6:
+ _wait()
+ self.assertEqual(results1 + results2, [0] * 6)
+ phase_num = 1
+ sem.release(7)
+ while len(results1) + len(results2) < 13:
+ _wait()
+ self.assertEqual(sorted(results1 + results2), [0] * 6 + [1] * 7)
+ phase_num = 2
+ sem.release(6)
+ while len(results1) + len(results2) < 19:
+ _wait()
+ self.assertEqual(sorted(results1 + results2), [0] * 6 + [1] * 7 + [2] * 6)
+ # The semaphore is still locked
+ self.assertFalse(sem.acquire(False))
+ # Final release, to let the last thread finish
+ sem.release()
+ b.wait_for_finished()
+
def test_try_acquire(self):
sem = self.semtype(2)
self.assertTrue(sem.acquire(False))