pub struct BasicSpinMutex<T, const PAUSE: bool>
This is a low-level synchronization primitive that spins on a busy loop rather than blocking the
thread. It's most appropriate for very short critical sections where the cost of context
switching would be higher than busy-waiting.
The generic parameter P allows customization of the pause behavior:
true enables CPU-specific pause instructions, recommended for most use cases
false disables pause instructions, which may be useful in specialized scenarios
Examples
use forkunion::*;
// Create a spin mutex with pause instructions enabled
let mutex = BasicSpinMutex::<i32, true>::new(42);
// Lock, access data, and unlock
{
let mut guard = mutex.lock();
*guard = 100;
} // Lock is automatically released when guard goes out of scope
// Verify the value was changed
assert_eq!(*mutex.lock(), 100);
Fast for short critical sections but spins continuously. Use when latency matters more than CPU
usage. Avoid for long critical sections or high contention scenarios.
Implements
Send, Sync