3 ms·
Another offender is AtomicWaker [1] which does the same on contention. [1] https://docs.rs/atomic-waker/latest/atomic_waker/ https://docs.rs/atomic-waker/lates
by binarycoffee 2y ago
Another offender is AtomicWaker [1] which does the same on contention.
[1] https://docs.rs/atomic-waker/latest/atomic_waker/ https://docs.rs/atomic-waker/latest/atomic_waker/
- SabrinaJewson 2y agoAtomicWaker is much less bad, because it will only spin in the case that another thread has spuriously called `wake` – i.e. called `wake` despite that fact that the future it’s waking is in fact unable to progress. In the common case, the waker side will operate some logic like: set_flag(); atomic_waker.wake(); and the future will run: atomic_waker.register(cx.waker()); if flag_is_set() { Poll::Ready(()) } else { Poll::Pending } Thus, even if `register` decides to “spin”, the flag will already be set, and so the future will not spin in reality (it may be polled unnecessarily, but this will only happen once). I can’t immediately think of examples where support for spurious waking is necessary.
- binarycoffee 2y agoThe producers of an MPSC queue may use an AtomicWaker::wake to signal to the consumer that a new item is ready. In this case all wake-ups are necessary (not spurious).