Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl_Finalize does not stop Tcl_Main (started in a thread)

Closed / Rejected219407ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 25 years ago
Descriptionplain2000-10-26 05:12:32
OriginalBugID: 6324 Bug
Version: 8.3.2
SubmitDate: '2000-09-28'
LastModified: '2000-10-25'
Severity: CRIT
Status: UnAssn
Submitter: techsupp
OS: Linux-Red Hat
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'


Name:
Sree Oggu

Extensions:
tcl 8.3.2

ReproducibleScript:
// The folllowing c++ program does not exit

#include "tcl.h"
#include <pthread.h>
#include <iostream.h>


int
Tcl_AppInit (Tcl_Interp *interp)
{
    return Tcl_Init(interp);
}

void*
Start (void* arg)
{
    char* argv = "dummy";
    Tcl_Main (1, &argv, Tcl_AppInit);
    return 0;
}


main (int argc, char** argv)
{
    pthread_t thr;

    pthread_create(&thr, 0, Start, 0);

    Tcl_Finalize();

    pthread_join (thr, 0);

    cout << "Terminating" << endl;
}

ObservedBehavior:
Use the followng command to compile the above program

g++ main.cc -ltcl -lpthread

DesiredBehavior:
I expect the program to terminate, since Tcl_Finalize has been invoked .
dkfplain2001-01-27 22:26:52
I suspect that this bug report might stem from a misunderstanding of the purpose of Tcl_Finalize...
dkf Ticket [219407ffff]: 1 change [History diff]2001-01-31 17:43:11
davygrvyplain2001-09-09 07:07:11
Logged In: YES 
user_id=7549

That's rather scary looking.  Tcl_Main wasn't meant to be a 
child.  This can't be correct usage of Tcl_Main?

And why should it stop it?  Why is Tcl_Finalize() supposed 
to forcefully terminate child threads?

Just my 2 cents...  I'm not sure of the "correct" answer.
davygrvyplain2001-09-09 08:32:27
Logged In: YES 
user_id=7549

I didn't catch it before, but I see a typo now.  
TCL_THREADS=1 is missing from the gcc commandline.  And I  
think Tcl_CreateThread() should be used in place of 
pthread_create(), but I might be cutting hairs on that 
comment.

I'd give it a shot, but I don't run *nix here.
dkf Ticket [219407ffff]: 1 change [History diff]2002-04-27 05:43:32
davygrvyplain2002-05-28 08:16:33
Logged In: YES 
user_id=7549

Tcl_Finalize() is used for clean-up.  It's job doesn't include the 
stopping of threads whether they are known by Tcl or not.  As 
a user of threads, it would be your job to do your own clean-
up.  I can not say that this new duty should be added to 
Tcl_Finalize().
dgpplain2002-05-30 05:57:05
Logged In: YES 
user_id=80530

Just to add a clarification, Tcl_Main() is only
a convenience routine for people who are creating
their own single-threaded shell programs.  It is
not suitable for multi-threaded use, as it uses
global variables.
davygrvyplain2002-05-31 04:58:04
Logged In: YES 
user_id=7549

If threads are in use by, for example, the thread extension, 
then the exit handler for it *should* send [thread::unwind]s to 
all threads in use...

At least the concept makes sense.  I should talk to Zoran 
about this to see if it does.  A controlled tear-down is a 
complicated thing with threads involed.  Is that thread blocked 
on a system call?  How do we interupt it?  Should we care?  
The announcement to exit is from another thread than the one 
we want to close, so how can we inject shutdown notices to 
them if they are blocked and not in the event loop?  Yuck.
Log in (anonymous is fine) to add a comment.