pub struct Mutex<T> { /* private fields */ }
Expand description
Atomic mutual exclusion
similar to std::sync::Mutex
.
A mutex can be used
- as a simple and efficient form of communication between tasks, by synchronizing acces to share data between multiple tasks
- to protect data races on shared data or peripherals
Example
Implementations
sourceimpl<T> Mutex<T>
impl<T> Mutex<T>
pub fn new(element: T) -> Self
sourcepub fn try_lock(&self) -> Result<MutexGuard<'_, T>, Error>
pub fn try_lock(&self) -> Result<MutexGuard<'_, T>, Error>
Try to lock the mutex (non-blocking). Returns a MutexGuard
or an
error if the mutex is not available or poisoned.
sourcepub fn lock(&self, timeout: u32) -> Result<MutexGuard<'_, T>, Error>
pub fn lock(&self, timeout: u32) -> Result<MutexGuard<'_, T>, Error>
Try to lock the mutex (blocking). Returns a MutexGuard
or an
error if the request timed out or the mutex was poisoned.
Note: The timeout function is not implemented yet.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for Mutex<T>
impl<T> Send for Mutex<T> where
T: Send,
impl<T> Unpin for Mutex<T> where
T: Unpin,
impl<T> UnwindSafe for Mutex<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more