diff options
author | Tim Peters <tim@python.org> | 2013-10-09 01:55:51 (GMT) |
---|---|---|
committer | Tim Peters <tim@python.org> | 2013-10-09 01:55:51 (GMT) |
commit | 7634e1cf9028ed5b21f0a97db45c91d8e8a159a6 (patch) | |
tree | ad1fe9e98197bb607b5e833df4df62c34e75937e /Lib/test | |
parent | ee82d0b29355df56744962b51563f24c4d2a6102 (diff) | |
download | cpython-7634e1cf9028ed5b21f0a97db45c91d8e8a159a6.zip cpython-7634e1cf9028ed5b21f0a97db45c91d8e8a159a6.tar.gz cpython-7634e1cf9028ed5b21f0a97db45c91d8e8a159a6.tar.bz2 |
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_threading.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index fef3314..0ebeb39 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -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 |