Multithreading 为什么TCL线程不打印输出

Multithreading 为什么TCL线程不打印输出,multithreading,tcl,Multithreading,Tcl,我使用的是TCL线程。我正在尝试编写一个简单的程序,它将打开3个线程,每个线程中只包含一个简单的print语句 下面是我的代码 package require Thread 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

我使用的是TCL线程。我正在尝试编写一个简单的程序,它将打开3个线程,每个线程中只包含一个简单的print语句

下面是我的代码

package require Thread
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!"

从您使用Tcl 8.4的评论中,您得到的建议很简单:升级到支持的Tcl版本。我已经尝试了您在OSX上发布的tclsh8.5和tclsh8.6代码,它们都产生了人们可能期望的输出。下面是8.5版的跑步:

*** I'm thread tid0x7fff758f3180 *** Started thread tid0x104326000 *** Started thread tid0x1043ac000 *** Started thread tid0x1044b2000 *** Existing threads: tid0x1044b2000 tid0x1043ac000 tid0x104326000 tid0x7fff758f3180 Thread tid0x1043ac000 says hello Thread tid0x104326000 says hello Thread tid0x104326000 says hello Thread tid0x1044b2000 says hello Thread tid0x1043ac000 says hello Thread tid0x1044b2000 says hello Thread tid0x104326000 says hello Thread tid0x1044b2000 says hello Thread tid0x1043ac000 says hello *** That's all, folks! ***我是线程tid0x7fff758f3180 ***已启动线程tid0x104326000 ***已启动线程tid0x1043ac000 ***已启动线程tid0x1044b2000 ***现有线程:tid0x1044b2000 tid0x1043ac000 tid0x104326000 tid0x7fff758f3180 线程tid0x1043ac000表示你好 线程tid0x104326000表示你好 线程tid0x104326000表示你好 线程tid0x1044b2000说你好 线程tid0x1043ac000表示你好 线程tid0x1044b2000说你好 线程tid0x104326000表示你好 线程tid0x1044b2000说你好 线程tid0x1043ac000表示你好 ***就这些,伙计们! 线程ID在其他平台上可能有很大的不同(它们的格式不属于规范的一部分),但这应该是您得到的类型。当然,排序中的模变化


Tcl 8.4甚至不再支持安全修复;在8.4.20发布后,它的使用寿命就结束了。

当我尝试这个确切的代码时,它对我很有用。它打印的是什么?您能在中使用Tcl 8.4显示outputI am吗windows@DonalFellows:我的要求是生成多个进程并获得输出。除了线程,还有其他解决方案吗?同样的代码对我来说也适用。。尝试在tclsh8.6中执行相同的代码。我使用的是8.6版本。我的问题是,线程包是否内置在tclsh8.6中?当我尝试使用tclsh8.4访问线程时,其中的线程包不存在。我的理解正确吗?线程包在8.4中是外部的。它应该出现在8.6中,除非有人做了一个真正简单的构建,跳过了所有贡献的包。 *** I'm thread tid0x7fff758f3180 *** Started thread tid0x104326000 *** Started thread tid0x1043ac000 *** Started thread tid0x1044b2000 *** Existing threads: tid0x1044b2000 tid0x1043ac000 tid0x104326000 tid0x7fff758f3180 Thread tid0x1043ac000 says hello Thread tid0x104326000 says hello Thread tid0x104326000 says hello Thread tid0x1044b2000 says hello Thread tid0x1043ac000 says hello Thread tid0x1044b2000 says hello Thread tid0x104326000 says hello Thread tid0x1044b2000 says hello Thread tid0x1043ac000 says hello *** That's all, folks!