mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Charles Waldman's patch to reinitialize the interpreter lock after a
fork. This solves the test_fork1 problem. (ceval.c, signalmodule.c, intrcheck.c) SourceForge: [ Patch #101226 ] make threading fork-safe
This commit is contained in:
parent
c79519569d
commit
fee3a2dd8c
3 changed files with 23 additions and 0 deletions
|
@ -667,6 +667,7 @@ void
|
||||||
PyOS_AfterFork(void)
|
PyOS_AfterFork(void)
|
||||||
{
|
{
|
||||||
#ifdef WITH_THREAD
|
#ifdef WITH_THREAD
|
||||||
|
PyEval_ReInitThreads();
|
||||||
main_thread = PyThread_get_thread_ident();
|
main_thread = PyThread_get_thread_ident();
|
||||||
main_pid = getpid();
|
main_pid = getpid();
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -195,4 +195,7 @@ PyOS_InterruptOccurred(void)
|
||||||
void
|
void
|
||||||
PyOS_AfterFork(void)
|
PyOS_AfterFork(void)
|
||||||
{
|
{
|
||||||
|
#ifdef WITH_THREAD
|
||||||
|
PyEval_ReInitThreads();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,6 +142,25 @@ PyEval_ReleaseThread(PyThreadState *tstate)
|
||||||
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
|
Py_FatalError("PyEval_ReleaseThread: wrong thread state");
|
||||||
PyThread_release_lock(interpreter_lock);
|
PyThread_release_lock(interpreter_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This function is called from PyOS_AfterFork to ensure that newly
|
||||||
|
created child processes don't hold locks referring to threads which
|
||||||
|
are not running in the child process. (This could also be done using
|
||||||
|
pthread_atfork mechanism, at least for the pthreads implementation.) */
|
||||||
|
|
||||||
|
void
|
||||||
|
PyEval_ReInitThreads(void)
|
||||||
|
{
|
||||||
|
if (!interpreter_lock)
|
||||||
|
return;
|
||||||
|
/*XXX Can't use PyThread_free_lock here because it does too
|
||||||
|
much error-checking. Doing this cleanly would require
|
||||||
|
adding a new function to each thread_*.h. Instead, just
|
||||||
|
create a new lock and waste a little bit of memory */
|
||||||
|
interpreter_lock = PyThread_allocate_lock();
|
||||||
|
PyThread_acquire_lock(interpreter_lock, 1);
|
||||||
|
main_thread = PyThread_get_thread_ident();
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions save_thread and restore_thread are always defined so
|
/* Functions save_thread and restore_thread are always defined so
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue