NonBlockingMutex
NonBlockingMutex
is needed to run actions
atomically without thread blocking, or context
switch, or spin lock contention, or rescheduling
on some scheduler
NonBlockingMutex
is faster than std::sync::Mutex
(both blocking and spinning)
when contention is high enough
Notice that NonBlockingMutex
doesn't guarantee order
of execution, only atomicity of operations is guaranteed
```rust use nonblockingmutex::NonBlockingMutex; use std::thread::{available_parallelism};
let maxconcurrentthreadcount = availableparallelism().unwrap().get();
let nonblockingmutex = NonBlockingMutex::new(maxconcurrentthreadcount, 0); nonblockingmutex.runiffirstorscheduleon_first(|mut state| { *state += 1; }); ```