Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a233df8

Browse files
author
Charles-François Natali
committed
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).
1 parent 3be0095 commit a233df8

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

Python/pystate.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,9 +592,9 @@ _PyGILState_Fini(void)
592592
autoInterpreterState = NULL;
593593
}
594594

595-
/* Reset the TLS key - called by PyOS_AfterFork.
595+
/* Reset the TLS key - called by PyOS_AfterFork().
596596
* This should not be necessary, but some - buggy - pthread implementations
597-
* don't flush TLS on fork, see issue #10517.
597+
* don't reset TLS upon fork(), see issue #10517.
598598
*/
599599
void
600600
_PyGILState_Reinit(void)
@@ -604,8 +604,9 @@ _PyGILState_Reinit(void)
604604
if ((autoTLSkey = PyThread_create_key()) == -1)
605605
Py_FatalError("Could not allocate TLS entry");
606606

607-
/* re-associate the current thread state with the new key */
608-
if (PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
607+
/* If the thread had an associated auto thread state, reassociate it with
608+
* the new key. */
609+
if (tstate && PyThread_set_key_value(autoTLSkey, (void *)tstate) < 0)
609610
Py_FatalError("Couldn't create autoTLSkey mapping");
610611
}
611612

0 commit comments

Comments
 (0)