diff options
author | Tim Peters <tim@python.org> | 2013-10-08 20:55:51 -0500 |
---|---|---|
committer | Tim Peters <tim@python.org> | 2013-10-08 20:55:51 -0500 |
commit | 7f3c434994a1d2c1669e8356215bc5474de6a1b3 (patch) | |
tree | 02935622d20682729242ecb5e830f32995c5738a /Lib/test | |
parent | f86bcaf25a8649a56bf0793cb44d4605c3e33a59 (diff) | |
download | cpython-7f3c434994a1d2c1669e8356215bc5474de6a1b3.tar.gz |
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 fef3314c16..0ebeb39cbd 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 |