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§
Auto Trait Implementations§
impl Freeze for Spin
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 0 bytes