diff options
author | Charles-François Natali <neologix@free.fr> | 2012-02-02 19:37:29 (GMT) |
---|---|---|
committer | Charles-François Natali <neologix@free.fr> | 2012-02-02 19:37:29 (GMT) |
commit | 227e377b36378d4cc86c3dd182f8d7c031e41f86 (patch) | |
tree | 7e08234547256c0148e5b927ecd83a2ba0c7daf6 | |
parent | 9713321f46769f41f653a752ec348cec766e633e (diff) | |
parent | 6d0d24e359b6d8a72a20c2091bbea0e16170d767 (diff) | |
download | cpython-227e377b36378d4cc86c3dd182f8d7c031e41f86.zip cpython-227e377b36378d4cc86c3dd182f8d7c031e41f86.tar.gz cpython-227e377b36378d4cc86c3dd182f8d7c031e41f86.tar.bz2 |
Merge.
-rw-r--r-- | Lib/test/test_threading.py | 23 | ||||
-rw-r--r-- | Modules/signalmodule.c | 4 |
2 files changed, 26 insertions, 1 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 diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 87c1c9a..32cd8bb 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -991,11 +991,13 @@ void PyOS_AfterFork(void) { #ifdef WITH_THREAD + /* PyThread_ReInitTLS() must be called early, to make sure that the TLS API + * can be called safely. */ + PyThread_ReInitTLS(); _PyGILState_Reinit(); PyEval_ReInitThreads(); main_thread = PyThread_get_thread_ident(); main_pid = getpid(); _PyImport_ReInitLock(); - PyThread_ReInitTLS(); #endif } |