summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixNotfy.c
diff options
context:
space:
mode:
authorhobbs <hobbs>2000-04-24 23:32:13 (GMT)
committerhobbs <hobbs>2000-04-24 23:32:13 (GMT)
commite38c8fdd49d388071ea563f8a0a8fada898eefd9 (patch)
tree50b19f689249d3877bc99eca02c7d44395247a21 /unix/tclUnixNotfy.c
parentf01e61ac300d8ce4e10dc60e0510a2409a969bf6 (diff)
downloadtcl-e38c8fdd49d388071ea563f8a0a8fada898eefd9.zip
tcl-e38c8fdd49d388071ea563f8a0a8fada898eefd9.tar.gz
tcl-e38c8fdd49d388071ea563f8a0a8fada898eefd9.tar.bz2
* unix/tclUnixNotfy.c (Tcl_FinalizeNotifier, NotifierThreadProc):
added write of 'q' into triggerPipe for notifier in threaded case, so that Tcl doesn't hang when children are still running [Bug: 4139] * unix/tclUnixThrd.c (Tcl_MutexLock): minor comment fixes.
Diffstat (limited to 'unix/tclUnixNotfy.c')
-rw-r--r--unix/tclUnixNotfy.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/unix/tclUnixNotfy.c b/unix/tclUnixNotfy.c
index 7d63228..f376746 100644
--- a/unix/tclUnixNotfy.c
+++ b/unix/tclUnixNotfy.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixNotfy.c,v 1.9 2000/04/09 16:04:20 kupries Exp $
+ * RCS: @(#) $Id: tclUnixNotfy.c,v 1.10 2000/04/24 23:32:13 hobbs Exp $
*/
#include "tclInt.h"
@@ -264,7 +264,20 @@ Tcl_FinalizeNotifier(clientData)
if (triggerPipe < 0) {
panic("Tcl_FinalizeNotifier: notifier pipe not initialized");
}
+
+ /*
+ * Send "q" message to the notifier thread so that it will
+ * terminate. The notifier will return from its call to select()
+ * and notice that a "q" message has arrived, it will then close
+ * its side of the pipe and terminate its thread. Note the we can
+ * not just close the pipe and check for EOF in the notifier
+ * thread because if a background child process was created with
+ * exec, select() would not register the EOF on the pipe until the
+ * child processes had terminated. [Bug: 4139]
+ */
+ write(triggerPipe, "q", 1);
close(triggerPipe);
+
Tcl_ConditionWait(&notifierCV, &notifierMutex, NULL);
}
@@ -963,10 +976,10 @@ NotifierThreadProc(clientData)
Tcl_ConditionNotify(&tsdPtr->waitCV);
if (tsdPtr->onList) {
/*
- * Remove the ThreadSpecificData structure of this thread
- * from the waiting list. This prevents us from continuously
- * spining on select until the other threads runs and
- * services the file event.
+ * Remove the ThreadSpecificData structure of this
+ * thread from the waiting list. This prevents us from
+ * continuously spining on select until the other
+ * threads runs and services the file event.
*/
if (tsdPtr->prevPtr) {
@@ -991,13 +1004,18 @@ NotifierThreadProc(clientData)
* to avoid a race condition we only read one at a time.
*/
- if ((masks[index] & bit) && (read(receivePipe, buf, 1) == 0)) {
- /*
- * Someone closed the write end of the pipe so we need to
- * shut down the notifier thread.
- */
+ if (masks[index] & bit) {
+ i = read(receivePipe, buf, 1);
- break;
+ if ((i == 0) || ((i == 1) && (buf[0] == 'q'))) {
+ /*
+ * Someone closed the write end of the pipe or sent us a
+ * Quit message [Bug: 4139] and then closed the write end
+ * of the pipe so we need to shut down the notifier thread.
+ */
+
+ break;
+ }
}
}