Tcl Source Code

View Ticket
Login
Ticket UUID: 749639
Title: exit fom child process hangs if --enable-threads set
Type: Bug Version: obsolete: 8.4.3
Submitter: dizzi Created on: 2003-06-05 16:31:15
Subsystem: 49. Threading Assigned To: andreas_kupries
Priority: 8 Severity:
Status: Closed Last Modified: 2011-09-24 05:11:25
Resolution: Fixed Closed By: ferrieux
    Closed on: 2011-09-23 22:11:25
Description:
When compiled with --enable-threads Tcl8.4.3 doesn't handle
correctly the exit from child processes created with
fork if they
don't execl some other program.

The problem is explained in detail in this bug report
against TclX
that I filed yesterday, which seems in fact a Tcl8.4 bug:

http://sourceforge.net/tracker/index.php?func=detail&aid=748835&group_id=13247&atid=113247

The problem seems to be that when the child process
exits without
executing another program it sends a 'q' message to a
notifier
process that belongs to its parent. The child then
waits for some
signal from the parent that is never sent and hangs
forever.

It is true that Tcl doesn't have the fork and execl
commands, but
these commands are provided by the TclX extension and they
can't work correctly because of a bug in the Tcl exit code.

The patch in attachment seems to fix the problem, but
since I don't
really know how the threaded notifier works it may be
wrong.

My solution simply does nothing in
Tcl_FinalizeNotifier() if the
current process is not the one which created the
notifier thread.
In this way the notifier thread can be terminated only
by its parent
and child processes should be able to exit without
interfering with
the parent threads.

-- 
Massimo Dal Zotto <[email protected]>
User Comments: ferrieux added on 2011-09-24 05:11:25:
Wiped out by the 2001201 quick exit reform.

davidw added on 2004-03-25 19:26:41:
Logged In: YES 
user_id=240

Since it's apparently not possible to actually attach a
patch, it is located at:

http://sourceforge.net/tracker/index.php?func=detail&aid=923072&group_id=10894&atid=310894

davidw added on 2004-03-25 19:19:27:
Logged In: YES 
user_id=240

Jeff Hobbs created a patch which uses pthread_atfork, which
is really what needs to happen.  The patch locks all the
mutexes before forking, then unlocks them in both the parent
and child afterwards.

I have cleaned up the patch just a bit, added 2 test
commands (testfork and testwaitpid), and a couple of basic
tests.

One modification to the patch that needs more thinking is
how to expose the atfork stuff to Tcl.  For starters, I have
created two functions, one that is called in the parent, the
other in the child.  Otherwise, there seems to be no way of
knowing which you are running in, and that information might
be necessary at some point.

gnepp added on 2003-07-02 05:22:28:
Logged In: YES 
user_id=698369

I think this is slightly wrong --
    Tcl_ConditionFinalize(&(tsdPtr->waitCV));
is no longer called in the child process but still needs to be.

An alternative patch would be to set notifierCount = 0 post-
fork in the child, using a pthread_atfork() handler, but I don't 
know how portable that is.

Andrei

dizzi added on 2003-06-05 23:31:15:

File Added - 52276: unix-notify.patch

Attachments: