-
Notifications
You must be signed in to change notification settings - Fork 517
Open
Labels
Description
Hi crossbeam-rs maintainers,
It is sometimes useful to know the status of an unpark operation, for example in a rayon-style thread pool where we need to heuristically wake a thread for incoming tasks:
// We have a new task, so we call this function to wake a thread to do the task if appropriate.
fn wake_one(&self) {
let (idle_count, asleep_count) = self.counter.get();
// If there are no awake idle threads to do the task, but there are asleep ones, wake one up.
if idle_count == 0 && asleep_count > 0 {
for unparker in self.unparkers {
let old_state = unparker.unpark_returning(); // Imaginary API
if old_state == ParkState::Parked { break; }
}
}
}Having an Unparker::unpark_returning() -> ParkState here would be helpful since it avoids the alternatives:
- Having to call
unpark()on all threads, introducing more wakeups and swaps than necessary. - Have some other atomic variable external to
Unparkerthat tracks sleep states, complicating the code.