#########################################################
package require Thread 2.5
puts "*** I'm thread [thread::id]"
# Create 3 threads
for {set thread 1} {$thread <= 3} {incr thread} {
set id [thread::create {
# Print a hello message 3 times, waiting
# a random amount of time between messages
for {set i 1} {$i <= 3} {incr i} {
after [expr { int(500*rand()) }]
puts "Thread [thread::id] says hello"
}
}] ;# thread::create
puts "*** Started thread $id"
} ;# for
puts "*** Existing threads: [thread::names]"
# Wait until all other threads are finished
while {[llength [thread::names]] > 1} {
after 500
}
puts "*** That's all, folks!"
thread::names
#########################################################
The tclsh result:
*** I'm thread 8872
*** Started thread 8968
*** Started thread 8964
*** Started thread 8928
*** Existing threads: 8928 8964 8968 8872
Thread 8968 says hello
Thread 8964 says hello
Thread 8964 says hello
Thread 8968 says hello
Thread 8928 says hello
Thread 8964 says hello
Thread 8968 says hello
Thread 8928 says hello
Thread 8928 says hello
*** That's all, folks!
8872
#########################################################
The wish result:
*** I'm thread 8860
*** Started thread 8980
*** Started thread 8832
*** Started thread 9008
*** Existing threads: 9008 8832 8980 8860
*** That's all, folks!
8860
#########################################################
Why the result is different between tclsh and wish ??
And are there anyone can give me the link about difference between
tclsh and wish.
Thanks all.
>Why the result is different between tclsh and wish ??
>And are there anyone can give me the link about difference between
>tclsh and wish.
The routine used to initialize the stdout the first time a call [puts],
[gets], etc is made is unable to find it because only the main threads
interp is blessed for redirection to the console widget.
See Tcl_AppInit() in win/winMain.c for:
if (consoleRequired) {
if (Tk_CreateConsoleWindow(interp) == TCL_ERROR) {
goto error;
}
}
When a threaded interp looks for the stdout channel for the first time,
it uses TclpGetDefaultStdChannel() but is unable to locate one, thus it
fails.
Yes, the console widget needs some way to hook itself into the innards in
some manner.
--
David Gravereaux <davy...@pobox.com>
[species: human; planet: earth,milkyway(western spiral arm),alpha sector]
Thank you very much.