Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2006-03-15
17:06 • Closed ticket [597997ffff]: async+thread panic plus 7 other changes artifact: 4744384ee9 user: msofer
07:59 • Ticket [597997ffff]: 4 changes artifact: d49ef9867d user: andreas_kupries
2004-04-01
20:47 • Ticket [597997ffff]: 4 changes artifact: 11d28bd50d user: msofer
2003-11-13
07:55 • Ticket [597997ffff]: 1 change artifact: b1b18a00f9 user: dgp
2002-08-22
21:21 • Ticket [597997ffff]: 4 changes artifact: 22de011b88 user: msofer
04:23 • Ticket [597997ffff]: 4 changes artifact: a7f7ca9c43 user: andreas_kupries
04:11 • Ticket [597997ffff]: 4 changes artifact: 2b52b8044c user: andreas_kupries
04:00 • Ticket [597997ffff]: 4 changes artifact: 1a51e39606 user: andreas_kupries
2002-08-20
23:06 • New ticket [597997ffff]. artifact: b658720eb7 user: msofer

async+thread panic

Closed / Duplicate597997ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 21 years ago
Descriptionplain2002-08-20 23:06:46
This (granted, stupid) script panics.

[mig@mini unix]$ cat /tmp/test.tcl 
lappend auto_path /CVS/thread/unix
package require Thread
proc spawn {} {
    global i imax forever
    after 10 spawn
    if {[incr i] <= $imax} {
        thread::create "puts $i"
        flush stdout
    }
    set forever 1
}

set i 0
if {[lindex $argv 0] ne {}} {
    set imax [lindex $argv 0]
} else {
    set imax 10
}
spawn
vwait forever
flush stdout

[mig@mini unix]$ ./tclsh /tmp/test.tcl 
1
called Tcl_FindHashEntry on deleted table
Aborted
andreas_kupriesplain2002-08-22 04:00:28
Logged In: YES 
user_id=75003

And here is a shell script to run the tcl script
until we get a core. It takes to long to get one
when doing this manually.

% while [ ! -f core ] ; do ./i/bin/tclsh8.4 tst.tcl ; done
andreas_kupriesplain2002-08-22 04:11:22
Logged In: YES 
user_id=75003

Well, the script reliably dumps core (panic, segfault, plain 
unwanted exit) ... Unfortunately the generated dumps are 
useless. Here is a typical stack trace

(gdb) where
#0  0x401d317e in __select () from /lib/libc.so.6
#1  0x400e9820 in ?? () from /home/andreask/sf-
dev/84/i//lib/libtcl8.4g.so
#2  0x400fab85 in pthread_start_thread (arg=0xbf7ffe40) at 
manager.c:241

Obviously something is smashing the stack(s) very badly.
andreas_kupriesplain2002-08-22 04:23:22
Logged In: YES 
user_id=75003

Adding a 'return' just after the 'flush stdout' in spawn makes 
the crash go away. What the change does is defer 'set forever 
1' until the chosen number of threads were created. This 
means that the 'vwait' at the end of the scripts exist only after 
the system is done with the threads.

Setting forever to one while still spawning a thread causes the 
system to sometimes exit vwait and the application while a 
spawned thread is still running and accessing shared data 
structures. In other words: This seems to be the same 
problem we already know about, i.e. do not exit the 
application until you are sure that all sub-thread are done. 
Just in a different guise.

See Tcl Bug #486399.
msoferplain2002-08-22 21:21:46
Logged In: YES 
user_id=148712

Mislabeled ticket, this has nothing to do with async and is
indeed an "exit before all threads returned": the following
script shows the same behaviour

    lappend auto_path /CVS/thread/unix
    package require Thread
    set i 0
    while {[incr i] <= 2} {
        thread::create "puts $i"
    }

and everything is fixed by adding the following at the end:

    # make sure to wait until all threads have returned
    # before exiting [bug #597997]
    while {[llength [thread::names]] > 1} {
        after 100 set x 1
        vwait x
    }
dgp Ticket [597997ffff]: 1 change [History diff]2003-11-13 07:55:05
msoferplain2004-04-01 20:47:23
Logged In: YES 
user_id=148712

Andreas: should we then relabel this bug and close it as
duplicate?
andreas_kupriesplain2006-03-15 07:59:21
Logged In: YES 
user_id=75003

Yes.
msoferplain2006-03-15 17:06:54
Logged In: YES 
user_id=148712

Closed as dup of #486399.
Log in (anonymous is fine) to add a comment.