pub struct Backoff { /* private fields */ }
Expand description
Makes the current thread to wait in the short time.
It should be used to implement wait-retry in high contention multithreading environment because of improving performance significantly.
It should not be used to replace other blocking mechanism.
Implementations§
Source§impl Backoff
impl Backoff
pub fn reset(&self)
Sourcepub fn spin(&self)
pub fn spin(&self)
Backs off in a lock-free loop.
This method should be used when we need to retry an operation because another thread made progress.
The processor may yield using the YIELD or PAUSE instruction.
Sourcepub fn snooze(&self)
pub fn snooze(&self)
Backs off in a blocking loop.
This method should be used when we need to wait for another thread to make progress.
The processor may yield using the YIELD or PAUSE instruction and the current thread may yield by giving up a time slice to the OS scheduler.
Sourcepub fn snooze_completed(&self) -> bool
pub fn snooze_completed(&self) -> bool
Backs off in a blocking loop.
This method should be used when we need to wait for another thread to make progress.
The processor may yield using the YIELD or PAUSE instruction and the current thread may yield by giving up a time slice to the OS scheduler.
Return true
to advise to stop using backoff and
block the current thread using a different synchronization mechanism instead.