Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Thread result is different in tclsh and wish ??

29 views
Skip to first unread message

Payton Chou

unread,
Nov 9, 2004, 3:38:52 AM11/9/04
to
Today I compile the following code with tclsh and wish. ( These code
comes from a book )

#########################################################
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.

David Gravereaux

unread,
Nov 9, 2004, 4:13:06 AM11/9/04
to
payto...@gmail.com (Payton Chou) wrote:

>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]

Payton Chou

unread,
Nov 10, 2004, 3:06:04 AM11/10/04
to
David Gravereaux <davy...@pobox.com> wrote in message news:<0t11p0d16i8l1t13k...@4ax.com>...

> 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.

Thank you very much.

0 new messages