diff Python/pystate.c @ 73694:ba90839c4993 3.2

Issue #13156: _PyGILState_Reinit(): Re-associate the auto thread state with the TLS key only if the thread that called fork() had an associated auto thread state (this might not be the case for example for a thread created outside of Python calling into a subinterpreter).
author Charles-François Natali <neologix@free.fr>
date Tue, 22 Nov 2011 19:49:51 +0100
parents 608975eafe86
children 5cc359804d61 aa6ce09d2350
line wrap: on
line diff
--- a/Python/pystate.c	Tue Nov 22 18:36:39 2011 +0100
+++ b/Python/pystate.c	Tue Nov 22 19:49:51 2011 +0100
@@ -592,9 +592,9 @@
     autoInterpreterState = NULL;
 }
 
-/* Reset the TLS key - called by PyOS_AfterFork.
+/* Reset the TLS key - called by PyOS_AfterFork().
  * This should not be necessary, but some - buggy - pthread implementations
- * don't flush TLS on fork, see issue #10517.
+ * don't reset TLS upon fork(), see issue #10517.
  */
 void
 _PyGILState_Reinit(void)
@@ -604,8 +604,9 @@
     if ((autoTLSkey = PyThread_create_key()) == -1)
         Py_FatalError("Could not allocate TLS entry");
 
-    /* re-associate the current thread state with the new key */
-    if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
+    /* If the thread had an associated auto thread state, reassociate it with
+     * the new key. */
+    if (tstate && PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
         Py_FatalError("Couldn't create autoTLSkey mapping");
 }