Multithreading Tcl TSV是否支持传递字典
我想通过TSV共享dict类型变量,但TSV文档没有显示对dict的任何支持。是否有其他方法可以通过线程共享dict变量?没有专门支持它;您通常会使用Multithreading Tcl TSV是否支持传递字典,multithreading,tcl,Multithreading,Tcl,我想通过TSV共享dict类型变量,但TSV文档没有显示对dict的任何支持。是否有其他方法可以通过线程共享dict变量?没有专门支持它;您通常会使用tsv::array来实现这类功能。但是,您也可以将值作为字符串放入锁中,作为字典进行处理,然后将结果写回 # assuming that the main thread shared variable is called FOO and we're using the BAR element of it tsv::lock FOO { #
tsv::array
来实现这类功能。但是,您也可以将值作为字符串放入锁中,作为字典进行处理,然后将结果写回
# assuming that the main thread shared variable is called FOO and we're using the BAR element of it
tsv::lock FOO {
# Read the dictionary out
set mycopy [tsv::get FOO BAR]
# Do some complicated operation
dict set mycopy "grill" [expr {2**[dict get $mycopy "quux"]}]
# Write the updated dictionary back
tsv::set FOO BAR $mycopy
}
在许多方面,基于列表的命令,如
tsv::lappend
是围绕基本get
/set
模式的包装,与此类似,只是包装是用C编写的。(TSV子包相当旧—它提供的API使我认为它与Tcl 8.4的上次更新时间相似—并且不提供字典的特定操作。)您也可以在TSV中使用键控列表支持。它们在语法上与dicts不同,但提供类似的基本操作。(我在执行初始的dict
实现时考虑过在dict中使用这种语法,但没有考虑,因为它使其他事情成为可能。)谢谢你的回答。这是否意味着TSV不是在主线程和工作线程之间共享引用数据的正确方法?有更好的方法吗?