rayon-rs/rayon

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

Open

#1135 opened on Feb 25, 2024

View on GitHub
 (4 comments) (0 reactions) (0 assignees)Rust (9,410 stars) (450 forks)batch import
help wanted

Description

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.

Contributor guide