]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #10517: After fork(), reinitialize the TLS used by the PyGILState_*
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 27 Apr 2011 17:28:05 +0000 (19:28 +0200)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 27 Apr 2011 17:28:05 +0000 (19:28 +0200)
APIs, to avoid a crash with the pthread implementation in RHEL 5.  Patch
by Charles-François Natali.

Include/pystate.h
Misc/NEWS
Modules/signalmodule.c
Python/pystate.c

index 50245c2c0adf1803662fa6a60b33a62425901e7d..9f876e98c4fa46110d9acfc64adca74a5fb40ce5 100644 (file)
@@ -131,6 +131,7 @@ PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
 PyAPI_FUNC(void) PyThreadState_Delete(PyThreadState *);
 #ifdef WITH_THREAD
 PyAPI_FUNC(void) PyThreadState_DeleteCurrent(void);
+PyAPI_FUNC(void) _PyGILState_Reinit(void);
 #endif
 
 PyAPI_FUNC(PyThreadState *) PyThreadState_Get(void);
index 005527f1cee7650a8046c567f5f2c14252919c35..5b150e79c4aa4128a67afddb2a99a4367f7e120e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,10 @@ What's New in Python 3.2.1?
 Core and Builtins
 -----------------
 
+- Issue #10517: After fork(), reinitialize the TLS used by the PyGILState_*
+  APIs, to avoid a crash with the pthread implementation in RHEL 5.  Patch
+  by Charles-François Natali.
+
 - Issue #6780: fix starts/endswith error message to mention that tuples are
   accepted too.
 
index d34f13246e9aef53421aff8effa0e335955a422f..00a83b497cd7ed26b693b71f778074e88e7a403c 100644 (file)
@@ -991,6 +991,7 @@ void
 PyOS_AfterFork(void)
 {
 #ifdef WITH_THREAD
+    _PyGILState_Reinit();
     PyEval_ReInitThreads();
     main_thread = PyThread_get_thread_ident();
     main_pid = getpid();
index 922e9a3780293f68a5bbc0171e985a3fe3520b1c..586b856603f7f38f802a103fc0b9f15215f65bba 100644 (file)
@@ -585,6 +585,23 @@ _PyGILState_Fini(void)
     autoInterpreterState = NULL;
 }
 
+/* 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.
+ */
+void
+_PyGILState_Reinit(void)
+{
+    PyThreadState *tstate = PyGILState_GetThisThreadState();
+    PyThread_delete_key(autoTLSkey);
+    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)
+        Py_FatalError("Couldn't create autoTLSkey mapping");
+}
+
 /* When a thread state is created for a thread by some mechanism other than
    PyGILState_Ensure, it's important that the GILState machinery knows about
    it so it doesn't try to create another thread state for the thread (this is