summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_threading.py
diff options
context:
space:
mode:
authorTim Peters <tim@python.org>2013-10-09 01:55:51 (GMT)
committerTim Peters <tim@python.org>2013-10-09 01:55:51 (GMT)
commit641d6217a839f42ccac6478ff7272dfef5c807e4 (patch)
treeaea0386f1c923fedc1eabe31542c77db573a0adc /Lib/test/test_threading.py
parent090588ec2ce134a0b2acd1e30be4f20db33a1d27 (diff)
downloadcpython-641d6217a839f42ccac6478ff7272dfef5c807e4.zip
cpython-641d6217a839f42ccac6478ff7272dfef5c807e4.tar.gz
cpython-641d6217a839f42ccac6478ff7272dfef5c807e4.tar.bz2
Issue 19158: a rare race in BoundedSemaphore could allow .release() too often.
(grafted from e06edc0c7a4951327f0c95ebeebccba6879a6063)
Diffstat (limited to 'Lib/test/test_threading.py')
-rw-r--r--Lib/test/test_threading.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 5a765f3..ac0b4bc 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -466,6 +466,23 @@ class ThreadTests(BaseTestCase):
finally:
sys.setcheckinterval(old_interval)
+ 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):