Struct ruspiro_lock::sync::Mutex [−][src]
#[repr(C, align(16))]pub struct Mutex<T: ?Sized> { /* fields omitted */ }
Expand description
An mutual exclusive access lock for the interior data
Implementations
Try to lock the interior data for mutual exclusive access. Returns None
if the lock failes
or Some(MutexGuard)
. The actual data, the MutexGuard wraps could be conviniently accessed by
dereferencing it.
Example
static DATA: Mutex<u32> = Mutex::new(10);
if let Some(data) = DATA.try_lock() {
// do something with data
}
Lock the guarded data for mutual exclusive access. This blocks until the data could be
successfully locked. The locked data will be returned as MutexGuard
. Simply dereferencing
this allows access to the contained data value.
Example
static DATA: Mutex<u32> = Mutex::new(10);
let mut data = DATA.lock();
// do something with data
*data = 15;
Consume the Mutex and return the inner value
Trait Implementations
The Mutex is always Sync
, to make it Send
as well it need to be wrapped into an Arc
.