rayon-rs/rayon

A yield_now/yield_local alternative that allows the thread to go to sleep

Open

#1,135 创建于 2024年2月25日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)Rust (9,410 star) (450 fork)batch import
help wanted

描述

We're investigating using rayon as Bevy's thread pool and scheduler, and part of that requires being able to schedule futures onto the task pool. This has been partially doable with the suggested implementations in the discussion in #679, but we're running into issues where futures::block_on equivalents cannot yield to the thread pool in a way that will put the thread to sleep if there is no available work, nor a way to, on-demand, wake that specificthread back up. futures_lite::block_on and it's variants park the thread using parking or the std equivalent in std::thread::park, but rayon does not expose any option for this level of control. Using the aforementioned options for parking the thread leads to excessive CPU usage and contention, likely due to conflicting with rayon's internal state of how threads should be managed.

A yield_sleep or yield_park equivalent that hooks into the internal thread sleeping state when called, and a corresponding data type that we can wrap as a Waker would be really useful here.

贡献者指南