Struct Mutex
pub struct Mutex<T> { /* private fields */ }
threading
only.Expand description
A basic mutex with priority inheritance.
Implementations§
§impl<T> Mutex<T>
impl<T> Mutex<T>
pub fn lock(&self) -> MutexGuard<'_, T>
pub fn lock(&self) -> MutexGuard<'_, T>
Acquires a mutex, blocking the current thread until it is able to do so.
If the mutex was unlocked, it will be locked and a MutexGuard
is returned.
If the mutex is locked, this function will block the current thread until the mutex gets
unlocked elsewhere.
If the current owner of the mutex has a lower priority than the current thread, it will inherit the waiting thread’s priority. The priority is reset once the mutex is released. This means that a user can not change a thread’s priority while it holds the lock, because it will be changed back after release!
§Panics
Panics if called outside of a thread context.
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
pub fn try_lock(&self) -> Option<MutexGuard<'_, T>>
Attempts to acquire this lock, in a non-blocking fashion.
If the mutex was unlocked, it will be locked and a MutexGuard
is returned.
If the mutex was locked None
is returned.