通过参考 TCL - 线程?
我正在使用 Snack 音频处理套件和 TCL。 我想切掉部分声音并将这部分交给另一个线程来处理。
我的问题是如何在 TCL 的线程之间通过引用传递某些内容。
proc a {} {
snack::sound snd
thread::send -async $Thread [list B snd]
}
set Thread [thead::create {
proc B{snd} {
... do something with snd
}
}
I'm using the Snack audio processing kit along with TCL.
I want to cut up part of the sound and give this section to another thread to work with.
My question is how to pass something by reference, between threads in TCL.
proc a {} {
snack::sound snd
thread::send -async $Thread [list B snd]
}
set Thread [thead::create {
proc B{snd} {
... do something with snd
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是行不通的。 Tcl 线程被设计为彼此强隔离,因为它大大减少了正常处理所需的锁定量。这样做的缺点是,在线程之间传递东西并不简单(除了包含命令的短消息,而音频数据则不然!)但是有一个前进的方法......
如果您可以将数据作为一大块发送字节(在脚本级别),那么我建议使用
tsv
包,它与 thread 包打包在一起,因此您已经拥有它了。这将使您能够相对简单地在线程之间传输数据。请注意,小吃包在其脚本级接口中不是线程感知的,因此数据传输仍然会涉及复制,并且 Tk(像许多 GUI 工具包,FWIW)不支持多线程使用(好吧,下次也不会没有技巧)所以如果您正在进行波形可视化,那么您还需要做一些工作。 (OTOH,现代 CPU 也有大量的空闲时间。)That's not going to work. Tcl threads are designed to be strongly isolated from each other since it massively reduces the amount of locking required for normal processing. The down-side of this is that passing things between threads is non-trivial (other than for short messages containing commands, which audio data isn't!) But there is a way forward…
If you can send the data as a chunk of bytes (at the script level) then I recommend transferring it between threads using the
tsv
package, which is parceled up with the thread package so you'll already have it. That will let you transport the data between threads relatively simply. Be aware that the snack package is not thread-aware in its script-level interface, so the data transfers are still going to involve copying, and Tk (like a great many GUI toolkits, FWIW) does not support multi-threaded use (well, not without techniques for another time) so if you're doing waveform visualization you've got some work ahead. (OTOH, modern CPUs have loads of time to spare too.)