0
我想在同步模式下发送消息给线程,并使用跟踪变量metohd得到结果。问题是我没有得到任何线程的回应。当我以正常模式发送消息(thread :: send thread_id {command} var)时,我也会得到保存在var中的结果。任何人都可以指出我犯错的地方吗?下面我通过我的代码:tcl thread :: send -async not working
trace add variable res write {apply {{v1 v2 op} {
upvar 1 $v1 v
puts "updated variable to $v"}}}
set th [thread::create {
puts "new thread id : [thread::id]"
proc fun {n} {
return [expr {$n*2}]
}
thread::wait
}]
# thread::send $th [list fun $t] res
thread::send -async $th [list fun 43] res
[线程手册页](http://www.tcl.tk/man/tcl/ThreadCmd/thread.htm)指出:“如果指定了-async标志,则该命令不会等待结果,并且它返回空字符串。“你期望发生什么?变量不会跨线程共享,并且不能跨线程跟踪。 –
感谢您的回答。我认为在一段时间后res值会改变,我将能够异步注册这个事件。有没有其他方法可以在不使用vwait的情况下在主线程中注册线程的末尾? – MacC