summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCharles-François Natali <neologix@free.fr>2012-02-02 19:31:42 (GMT)
committerCharles-François Natali <neologix@free.fr>2012-02-02 19:31:42 (GMT)
commit6d0d24e359b6d8a72a20c2091bbea0e16170d767 (patch)
treed7e06c5c3f4c289553ecf4a4a79521b4c8967f7f /Lib
parent03c29f90c37870d3a0a65524373acb5008fa7a11 (diff)
downloadcpython-6d0d24e359b6d8a72a20c2091bbea0e16170d767.zip
cpython-6d0d24e359b6d8a72a20c2091bbea0e16170d767.tar.gz
cpython-6d0d24e359b6d8a72a20c2091bbea0e16170d767.tar.bz2
Issue #13817: After fork(), reinit the ad-hoc TLS implementation earlier to fix
a random deadlock when fork() is called in a multithreaded process in debug mode, and make PyOS_AfterFork() more robust.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_threading.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py
index 924d9d3..e3de16d 100644
--- a/Lib/test/test_threading.py
+++ b/Lib/test/test_threading.py
@@ -666,6 +666,29 @@ class ThreadJoinOnShutdown(BaseTestCase):
rc, out, err = assert_python_ok('-c', script)
self.assertFalse(err)
+ @unittest.skipUnless(hasattr(os, 'fork'), "needs os.fork()")
+ def test_reinit_tls_after_fork(self):
+ # Issue #13817: fork() would deadlock in a multithreaded program with
+ # the ad-hoc TLS implementation.
+
+ def do_fork_and_wait():
+ # just fork a child process and wait it
+ pid = os.fork()
+ if pid > 0:
+ os.waitpid(pid, 0)
+ else:
+ os._exit(0)
+
+ # start a bunch of threads that will fork() child processes
+ threads = []
+ for i in range(16):
+ t = threading.Thread(target=do_fork_and_wait)
+ threads.append(t)
+ t.start()
+
+ for t in threads:
+ t.join()
+
class ThreadingExceptionTests(BaseTestCase):
# A RuntimeError should be raised if Thread.start() is called