【问题标题】:tcl thread::send -async not workstcl 线程::send -async 不起作用
【发布时间】:2017-07-08 16:30:55
【问题描述】:

我想以同步模式向线程发送消息并使用跟踪变量方法获取结果。问题是我没有得到线程的任何响应。当我以正常模式发送消息时(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

【问题讨论】:

  • thread manual page 声明:“如果指定了 -async 标志,则该命令不会等待结果并返回空字符串。”你期待会发生什么?变量不跨线程共享,无法跨线程追踪。
  • 感谢您的回答。我认为一段时间后 res 值会发生变化,我将能够异步注册此事件。还有其他方法可以在不使用 vwait 的情况下在主线程中注册线程的结尾吗?

标签: multithreading tcl


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2018-07-14
    • 1970-01-01
    • 2016-12-21
    • 2019-03-28
    • 2019-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-19
    相关资源
    最近更新 更多