File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ PyAPI_FUNC(void) PyThreadState_Clear(PyThreadState *);
132132PyAPI_FUNC (void ) PyThreadState_Delete (PyThreadState * );
133133#ifdef WITH_THREAD
134134PyAPI_FUNC (void ) PyThreadState_DeleteCurrent (void );
135+ PyAPI_FUNC (void ) _PyGILState_Reinit (void );
135136#endif
136137
137138PyAPI_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.3 Alpha 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 #10914: Initialize correctly the filesystem codec when creating a new
1418 subinterpreter to fix a bootstrap issue with codecs implemented in Python, as
1519 the ISO-8859-15 codec.
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 @@ -586,6 +586,23 @@ _PyGILState_Fini(void)
586586 autoInterpreterState = NULL ;
587587}
588588
589+ /* Reset the TLS key - called by PyOS_AfterFork.
590+ * This should not be necessary, but some - buggy - pthread implementations
591+ * don't flush TLS on fork, see issue #10517.
592+ */
593+ void
594+ _PyGILState_Reinit (void )
595+ {
596+ PyThreadState * tstate = PyGILState_GetThisThreadState ();
597+ PyThread_delete_key (autoTLSkey );
598+ if ((autoTLSkey = PyThread_create_key ()) == -1 )
599+ Py_FatalError ("Could not allocate TLS entry" );
600+
601+ /* re-associate the current thread state with the new key */
602+ if (PyThread_set_key_value (autoTLSkey , (void * )tstate ) < 0 )
603+ Py_FatalError ("Couldn't create autoTLSkey mapping" );
604+ }
605+
589606/* When a thread state is created for a thread by some mechanism other than
590607 PyGILState_Ensure, it's important that the GILState machinery knows about
591608 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