Struct spin::relax::Spin

source ·
pub struct Spin;
Expand description

A strategy that rapidly spins while informing the CPU that it should power down non-essential components via core::hint::spin_loop.

Note that spinning is a ‘dumb’ strategy and most schedulers cannot correctly differentiate it from useful work, thereby misallocating even more CPU time to the spinning process. This is known as ‘priority inversion’.

If you see signs that priority inversion is occurring, consider switching to [Yield] or, even better, not using a spinlock at all and opting for a proper scheduler-aware lock. Remember also that different targets, operating systems, schedulers, and even the same scheduler with different workloads will exhibit different behaviour. Just because priority inversion isn’t occurring in your tests does not mean that it will not occur. Use a scheduler- aware lock if at all possible.

Trait Implementations§

source§

impl RelaxStrategy for Spin

source§

fn relax()

Perform the relaxing operation during a period of contention.

Auto Trait Implementations§

§

impl RefUnwindSafe for Spin

§

impl Send for Spin

§

impl Sync for Spin

§

impl Unpin for Spin

§

impl UnwindSafe for Spin

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.