平行于生锈中的自我修饰循环

发布于 2025-01-21 15:42:40 字数 369 浏览 2 评论 0原文

我在Rust中有一个循环,基本上看起来像这样:

while let Some(next) = myqueue.pop_front() {
   let result = next.activate();
   if result.0 {
      myqueue.extend(result.1.into_iter());
   }
}

我想对此循环含糊。自然地,人造丝板条箱我想到了for_each循环执行的并行执行的问题,但是问题是要求Myqueue对象由主线程和子线程都拥有,因为已迭代的集合正在通过线程和线程修改。我不想使用不安全的块。因此,我被卡住了,想帮助人造丝创建(或一种完全不同的方法)。

欢迎任何帮助。

谢谢你!

I have a loop in Rust, which basically looks like this:

while let Some(next) = myqueue.pop_front() {
   let result = next.activate();
   if result.0 {
      myqueue.extend(result.1.into_iter());
   }
}

I want to paralelize this loop. Naturally, rayon crate came to my mind with the parallel executed for_each loop however the problem is that would require myqueue object to be owned by both the main thread and the child threads since the collection that is being iterated over is being modified by the threads and I do not want to use an unsafe block. Therefore, I got stuck and wanted to help with rayon create over this (or maybe a completely different approach).

Any and all help is welcome.

Thank you!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文