Multithreading tcl线程::发送-异步不起作用

Multithreading tcl线程::发送-异步不起作用,multithreading,tcl,Multithreading,Tcl,我想以同步模式向线程发送消息,并使用跟踪变量metohd获得结果。问题是我没有从线程得到任何响应。当我以正常模式发送消息(thread::send thread_id{command}var)时,我也会得到保存在var中的结果。有人能指出我在哪里出错吗?下面我传递我的代码: trace add variable res write {apply {{v1 v2 op} { upvar 1 $v1 v puts "updated variable to $v"}}} set th [th

我想以同步模式向线程发送消息,并使用跟踪变量metohd获得结果。问题是我没有从线程得到任何响应。当我以正常模式发送消息(thread::send thread_id{command}var)时,我也会得到保存在var中的结果。有人能指出我在哪里出错吗?下面我传递我的代码:

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

是否正在源/主线程中等待事件?否则,您将永远不会处理导致设置
res
变量的异步响应消息

状态为:“如果指定了-async标志,则命令不会等待结果,并返回空字符串。”您希望发生什么?变量不能跨线程共享,也不能跨线程跟踪。谢谢您的回答。我认为一段时间后res值会改变,我将能够异步注册此事件。有没有其他方法可以在不使用vwait的情况下在主线程中注册th线程的末尾?