Struct ReentrantMutex

Source
pub struct ReentrantMutex<T> { /* 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>

Source

pub fn new(t: T) -> ReentrantMutex<T>

Creates a new reentrant mutex in an unlocked state.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Debug + 'static> Debug for ReentrantMutex<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for ReentrantMutex<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send> Send for ReentrantMutex<T>

Source§

impl<T: Send> Sync for ReentrantMutex<T>

Auto Trait Implementations§

§

impl<T> !Freeze for ReentrantMutex<T>

§

impl<T> !RefUnwindSafe for ReentrantMutex<T>

§

impl<T> Unpin for ReentrantMutex<T>
where T: Unpin,

§

impl<T> UnwindSafe for ReentrantMutex<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.