summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authoroehhar <harald.oehlmann@elmicron.de>2013-07-17 16:02:36 (GMT)
committeroehhar <harald.oehlmann@elmicron.de>2013-07-17 16:02:36 (GMT)
commit6b9dcf87ecc79d795e79e3d6d8e03b894f36a6cc (patch)
tree8fb8201bc94a649c230d63ea3ef6a24b2d08b237 /unix
parenta398b126a43e46efa6d6044b0bcf57a4b9385c4e (diff)
downloadtcl-6b9dcf87ecc79d795e79e3d6d8e03b894f36a6cc.zip
tcl-6b9dcf87ecc79d795e79e3d6d8e03b894f36a6cc.tar.gz
tcl-6b9dcf87ecc79d795e79e3d6d8e03b894f36a6cc.tar.bz2
Start notifier thread again if we were forked, to solve Rivet bug 55153 - RFE [a0bc856dcd]
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixNotfy.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index aacc8d2d..2ad1932 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.c
@@ -120,6 +120,15 @@ static Tcl_ThreadDataKey dataKey;
static int notifierCount = 0;
/*
+ * The following static stores the process ID of the initialized notifier
+ * thread. If it changes, we have passed a fork and we should start a new
+ * notifier thread.
+ *
+ * You must hold the notifierMutex lock before accessing this variable.
+ */
+static pid_t processIDInitialized = 0;
+
+/*
* The following variable points to the head of a doubly-linked list of
* ThreadSpecificData structures for all threads that are currently waiting on
* an event.
@@ -275,11 +284,23 @@ Tcl_InitNotifier(void)
*/
Tcl_MutexLock(&notifierMutex);
+ /*
+ * Check if my process id changed, e.g. I was forked
+ * In this case, restart the notifier thread and close the
+ * pipe to the original notifier thread
+ */
+ if (notifierCount > 0 && processIDInitialized != getpid()) {
+ notifierCount = 0;
+ processIDInitialized = 0;
+ close(triggerPipe);
+ triggerPipe = -1;
+ }
if (notifierCount == 0) {
if (TclpThreadCreate(&notifierThread, NotifierThreadProc, NULL,
TCL_THREAD_STACK_DEFAULT, TCL_THREAD_JOINABLE) != TCL_OK) {
Tcl_Panic("Tcl_InitNotifier: unable to start notifier thread");
}
+ processIDInitialized = getpid();
}
notifierCount++;