| Ticket UUID: | 597997 | ||
| Title: | async+thread panic | ||
| Type: | Bug | Created on: | 2002-08-20 23:06:46 |
| Submitter: | msofer | Assigned to: | andreas_kupries |
| Subsystem: | 49. Threading | Severity: | |
| Priority: | 5 Medium | Last modified: | 2006-03-15 17:06:54 |
| Status: | Closed | Closed by: | msofer |
| Resolution: | Duplicate | Closed on: | 2006-03-15 10:06:54 |
| Version: | obsolete: 8.4.4 | ||
| Description: | ||||
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
| ||||
| User Comments: | ||||
andreas_kupries added on 2002-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_kupries added on 2002-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_kupries added on 2002-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. msofer added on 2002-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
}
msofer added on 2004-04-01 20:47:23:
Logged In: YES user_id=148712 Andreas: should we then relabel this bug and close it as duplicate? andreas_kupries added on 2006-03-15 07:59:21:
Logged In: YES user_id=75003 Yes. msofer added on 2006-03-15 17:06:54:
Logged In: YES user_id=148712 Closed as dup of #486399. | ||||
