diff Python/ceval.c @ 14225:cbe9590d2344 legacy-trunk

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
author Guido van Rossum <guido@python.org>
date Sun, 27 Aug 2000 17:34:07 +0000
parents 1b9fd0cbd914
children 1f1a156ed5af
line wrap: on
line diff
--- a/Python/ceval.c	Sat Aug 26 21:01:27 2000 +0000
+++ b/Python/ceval.c	Sun Aug 27 17:34:07 2000 +0000
@@ -142,6 +142,25 @@
 		Py_FatalError("PyEval_ReleaseThread: wrong thread state");
 	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
 
 /* Functions save_thread and restore_thread are always defined so