mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
This commit is contained in:
parent
ee82d0b293
commit
7634e1cf90
2 changed files with 23 additions and 3 deletions
|
@ -468,6 +468,24 @@ class ThreadTests(BaseTestCase):
|
|||
self.assertEqual(0, status)
|
||||
|
||||
|
||||
def test_BoundedSemaphore_limit(self):
|
||||
# BoundedSemaphore should raise ValueError if released too often.
|
||||
for limit in range(1, 10):
|
||||
bs = threading.BoundedSemaphore(limit)
|
||||
threads = [threading.Thread(target=bs.acquire)
|
||||
for _ in range(limit)]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
threads = [threading.Thread(target=bs.release)
|
||||
for _ in range(limit)]
|
||||
for t in threads:
|
||||
t.start()
|
||||
for t in threads:
|
||||
t.join()
|
||||
self.assertRaises(ValueError, bs.release)
|
||||
|
||||
class ThreadJoinOnShutdown(BaseTestCase):
|
||||
|
||||
# Between fork() and exec(), only async-safe functions are allowed (issues
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue