多个生产者和多个读者频道?

发布于 2025-01-22 07:48:00 字数 224 浏览 2 评论 0原文

是否可以在Rust中创建一个在Rust中的通道,并在Rust中读取数量的发送和读取?基本上,我想将几​​个任务发送到频道作为初始化的形式,然后以并行方式开始执行任务。但是问题是任务本身有时可以创建并将任务发送到频道。当所有任务都消耗时,渠道应关闭。我认为频道实现最适合这种特殊情况,但是RUST似乎没有多源 +多消费者频道实现。或者,如果我试图实施我不应该和 /或不可能实施的东西,也欢迎提供全新的范式的建议。

谢谢你!

Is it possible to create a channel in Rust with a non-determinate number of sends and reads in rust? Basically I want to send couple tasks up to channel as a form of an initialization and then start executing the tasks in a parallel way. But the problem is tasks themselves sometimes can create and send the tasks up to channel. The channel should close when all tasks have been consumed. I thought channel implementation would suit best for this particular case but Rust doesn't seem to have a multiproducer + multiconsumer channel implementation. Or suggestions of a completely new paradigm would also be welcome if I am trying to implement something I am not supposed to and / or is not possible.

Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

仅此而已 2025-01-29 07:48:00

您可以使用std :: Sync :: MPSCcrossbeam_channel正式更好,更快,但需要拉出外部板条箱。

std :: Sync :: mpsc的文档:
https://doc.rust-lust-lang.org/nightly/ std/sync/mpsc/index.html

crossbeam_channel的文档

You may use either std::sync::mpsc or crossbeam_channel the formal is better and faster but requires pulling an external crate.

Documentation of std::sync::mpsc:
https://doc.rust-lang.org/nightly/std/sync/mpsc/index.html

Documentation of crossbeam_channel:
https://docs.rs/crossbeam-channel/latest/crossbeam_channel/

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