通过参考 TCL - 线程?

发布于 2024-09-08 19:16:47 字数 291 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黯然#的苍凉 2024-09-15 19:16:47

那是行不通的。 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.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文