with_critical_section_mutex2

Function with_critical_section_mutex2 

Source
pub fn with_critical_section_mutex2<F, R, T1, T2>(
    _py: Python<'_>,
    m1: &PyMutex<T1>,
    m2: &PyMutex<T2>,
    f: F,
) -> R
where F: for<'s> FnOnce(EnteredCriticalSection<'s, T1>, EnteredCriticalSection<'s, T2>) -> R,
Expand description

Executes a closure with a Python critical section held on two PyMutex instances.

Simultaneously locks the mutexes m1 and m2 and holds them until the closure f is finished. The mutexes may be temporarily unlock and re-acquired if the closure calls back into the interpreter. See the notes in the pyo3::sync::critical_section module documentation for more details.

This is structurally equivalent to the use of the paired Py_BEGIN_CRITICAL_SECTION2_MUTEX and Py_END_CRITICAL_SECTION2 C-API macros.

A no-op on GIL-enabled builds, where the critical section API is exposed as a no-op by the Python C API.

ยงSafety

The caller must ensure the closure cannot implicitly release the critical section. See the safety notes in the documentation for pyo3::sync::critical_section::EnteredCriticalSection for more details.