pub struct ExponentialBackoff<const SPIN_LIMIT: usize, const UNTIL_UNCHANGED_LIMIT: usize = 0, const YIELD_AFTER: usize = { usize::MAX }> { /* private fields */ }Expand description
Performs exponential backoff.
Each backoff iteration iter (starting from 0) calls spin_loop 1 << iter.min(SPIN_LIMIT)
times.
During the first UNTIL_UNCHANGED_LIMIT backoff iterations, backoff continues until the
atomic’s value stops changing between reloads; after that, the CAS is retried after a single
reload to avoid starvation.
After YIELD_AFTER backoff iterations (and if the std feature is enabled), yield_now is
called instead of spinning.
For reference, crossbeam::utils::Backoff is equivalent to ExponentialBackoff<6> with
Backoff::spin, and ExponentialBackoff<10, 0, 7> with Backoff::snooze. However,
UNTIL_UNCHANGED_LIMIT should also be used in contended CAS loop to further reduce contention.
Implementations§
Source§impl<const SPIN_LIMIT: usize, const UNTIL_UNCHANGED_LIMIT: usize, const YIELD_AFTER: usize> ExponentialBackoff<SPIN_LIMIT, UNTIL_UNCHANGED_LIMIT, YIELD_AFTER>
impl<const SPIN_LIMIT: usize, const UNTIL_UNCHANGED_LIMIT: usize, const YIELD_AFTER: usize> ExponentialBackoff<SPIN_LIMIT, UNTIL_UNCHANGED_LIMIT, YIELD_AFTER>
Sourcepub fn starts_at(iter: usize) -> Self
pub fn starts_at(iter: usize) -> Self
Starts an exponential backoff at the given iteration (starting from 0).
This constructor can be used to skip the first smaller iterations.
Sourcepub fn iter_count(&self) -> usize
pub fn iter_count(&self) -> usize
Returns the current count of backoff iterations performed.
It can be used for example to switch to another algorithm, like thread parking, after a given iteration count.
Trait Implementations§
Source§impl<const SPIN_LIMIT: usize, const UNTIL_UNCHANGED_LIMIT: usize, const YIELD_AFTER: usize> BackoffStrategy for ExponentialBackoff<SPIN_LIMIT, UNTIL_UNCHANGED_LIMIT, YIELD_AFTER>
impl<const SPIN_LIMIT: usize, const UNTIL_UNCHANGED_LIMIT: usize, const YIELD_AFTER: usize> BackoffStrategy for ExponentialBackoff<SPIN_LIMIT, UNTIL_UNCHANGED_LIMIT, YIELD_AFTER>
Source§fn backoff(&mut self) -> RetryStrategy
fn backoff(&mut self) -> RetryStrategy
Source§fn will_reload(&self) -> bool
fn will_reload(&self) -> bool
Source§fn backoff_reload<T: PartialEq, F: FnMut() -> T>(
&mut self,
current: T,
reload: F,
) -> T
fn backoff_reload<T: PartialEq, F: FnMut() -> T>( &mut self, current: T, reload: F, ) -> T
RetryStrategy. Read more