Skip to main content

RwLockExt

Trait RwLockExt 

pub trait RwLockExt<T>: Sealed {
    type ReadLockResult<'a>
       where Self: 'a;
    type WriteLockResult<'a>
       where Self: 'a;

    // Required methods
    fn read_py_attached(&self, py: Python<'_>) -> Self::ReadLockResult<'_>;
    fn write_py_attached(&self, py: Python<'_>) -> Self::WriteLockResult<'_>;
}
Available on crate feature tls only.
Expand description

Extension trait for std::sync::RwLock which helps avoid deadlocks between the Python interpreter and acquiring the RwLock.

Required Associated Types§

type ReadLockResult<'a> where Self: 'a

The result type returned by the read_py_attached method.

type WriteLockResult<'a> where Self: 'a

The result type returned by the write_py_attached method.

Required Methods§

fn read_py_attached(&self, py: Python<'_>) -> Self::ReadLockResult<'_>

Lock this RwLock for reading in a manner that cannot deadlock with the Python interpreter.

Before attempting to lock the rwlock, this function detaches from the Python runtime. When the lock is acquired, it re-attaches to the Python runtime before returning the ReadLockResult. This avoids deadlocks between the GIL and other global synchronization events triggered by the Python interpreter.

fn write_py_attached(&self, py: Python<'_>) -> Self::WriteLockResult<'_>

Lock this RwLock for writing in a manner that cannot deadlock with the Python interpreter.

Before attempting to lock the rwlock, this function detaches from the Python runtime. When the lock is acquired, it re-attaches to the Python runtime before returning the WriteLockResult. This avoids deadlocks between the GIL and other global synchronization events triggered by the Python interpreter.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl<T> RwLockExt<T> for RwLock<T>

§

type ReadLockResult<'a> = Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>> where RwLock<T>: 'a

§

type WriteLockResult<'a> = Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>> where RwLock<T>: 'a

§

fn read_py_attached( &self, _py: Python<'_>, ) -> <RwLock<T> as RwLockExt<T>>::ReadLockResult<'_>

§

fn write_py_attached( &self, _py: Python<'_>, ) -> <RwLock<T> as RwLockExt<T>>::WriteLockResult<'_>

Implementors§