Struct td_rthreadpool::ReentrantMutex
source · pub struct ReentrantMutex<T: ?Sized> { /* private fields */ }
Expand description
A re-entrant mutual exclusion
This mutex will block other threads waiting for the lock to become available. The thread which has already locked the mutex can lock it multiple times without blocking, preventing a common source of deadlocks.
Implementations§
source§impl<T> ReentrantMutex<T>
impl<T> ReentrantMutex<T>
sourcepub fn new(t: T) -> ReentrantMutex<T>
pub fn new(t: T) -> ReentrantMutex<T>
Creates a new reentrant mutex in an unlocked state.
sourcepub fn lock(
&self
) -> Result<ReentrantMutexGuard<'_, T>, PoisonError<ReentrantMutexGuard<'_, T>>>
pub fn lock(
&self
) -> Result<ReentrantMutexGuard<'_, T>, PoisonError<ReentrantMutexGuard<'_, T>>>
Acquires a mutex, blocking the current thread until it is able to do so.
This function will block the caller until it is available to acquire the mutex. Upon returning, the thread is the only thread with the mutex held. When the thread calling this method already holds the lock, the call shall succeed without blocking.
Failure
If another user of this mutex panicked while holding the mutex, then this call will return failure if the mutex would otherwise be acquired.
sourcepub fn try_lock(
&self
) -> Result<ReentrantMutexGuard<'_, T>, TryLockError<ReentrantMutexGuard<'_, T>>>
pub fn try_lock(
&self
) -> Result<ReentrantMutexGuard<'_, T>, TryLockError<ReentrantMutexGuard<'_, T>>>
Attempts to acquire this lock.
If the lock could not be acquired at this time, then Err
is returned.
Otherwise, an RAII guard is returned.
This function does not block.
Failure
If another user of this mutex panicked while holding the mutex, then this call will return failure if the mutex would otherwise be acquired.