File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,6 +131,7 @@ PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
131131PyAPI_FUNC (void ) PyThreadState_Delete (PyThreadState * );
132132#ifdef WITH_THREAD
133133PyAPI_FUNC (void ) PyThreadState_DeleteCurrent (void );
134+ PyAPI_FUNC (void ) _PyGILState_Reinit (void );
134135#endif
135136
136137PyAPI_FUNC (PyThreadState * ) PyThreadState_Get (void );
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ What's New in Python 3.2.1?
1010Core and Builtins
1111-----------------
1212
13+ - Issue #10517: After fork(), reinitialize the TLS used by the PyGILState_*
14+ APIs, to avoid a crash with the pthread implementation in RHEL 5. Patch
15+ by Charles-François Natali.
16+
1317- Issue #6780: fix starts/endswith error message to mention that tuples are
1418 accepted too.
1519
Original file line number Diff line number Diff line change 991991PyOS_AfterFork (void )
992992{
993993#ifdef WITH_THREAD
994+ _PyGILState_Reinit ();
994995 PyEval_ReInitThreads ();
995996 main_thread = PyThread_get_thread_ident ();
996997 main_pid = getpid ();
Original file line number Diff line number Diff line change @@ -585,6 +585,23 @@ _PyGILState_Fini(void)
585585 autoInterpreterState = NULL ;
586586}
587587
588+ /* Reset the TLS key - called by PyOS_AfterFork.
589+ * This should not be necessary, but some - buggy - pthread implementations
590+ * don't flush TLS on fork, see issue #10517.
591+ */
592+ void
593+ _PyGILState_Reinit (void )
594+ {
595+ PyThreadState * tstate = PyGILState_GetThisThreadState ();
596+ PyThread_delete_key (autoTLSkey );
597+ if ((autoTLSkey = PyThread_create_key ()) == -1 )
598+ Py_FatalError ("Could not allocate TLS entry" );
599+
600+ /* re-associate the current thread state with the new key */
601+ if (PyThread_set_key_value (autoTLSkey , (void * )tstate ) < 0 )
602+ Py_FatalError ("Couldn't create autoTLSkey mapping" );
603+ }
604+
588605/* When a thread state is created for a thread by some mechanism other than
589606 PyGILState_Ensure, it's important that the GILState machinery knows about
590607 it so it doesn't try to create another thread state for the thread (this is
You can’t perform that action at this time.
0 commit comments