pub struct RawOneShotMutex { /* private fields */ }
Expand description
A one-shot mutex that panics instead of (dead)locking on contention.
This mutex allows no contention and panics instead of blocking on lock
if it is already locked.
This is useful in situations where contention would be a bug,
such as in single-threaded programs that would deadlock on contention.
This mutex should be used through OneShotMutex
.
§Examples
use one_shot_mutex::sync::OneShotMutex;
static X: OneShotMutex<i32> = OneShotMutex::new(42);
// This is equivalent to `X.try_lock().unwrap()`.
let x = X.lock();
// This panics instead of deadlocking.
// let x2 = X.lock();
// Once we unlock the mutex, we can lock it again.
drop(x);
let x = X.lock();
Implementations§
Trait Implementations§
Source§impl Default for RawOneShotMutex
impl Default for RawOneShotMutex
Source§impl RawMutex for RawOneShotMutex
impl RawMutex for RawOneShotMutex
Source§type GuardMarker = GuardSend
type GuardMarker = GuardSend
Marker type which determines whether a lock guard should be
Send
. Use
one of the GuardSend
or GuardNoSend
helper types here.