Module sync

Module sync 

Source
Expand description

Synchronization mechanisms which are aware of the existence of the Python interpreter.

The Python interpreter has multiple “stop the world” situations which may block threads, such as

  • The Python global interpreter lock (GIL), on GIL-enabled builds of Python, or
  • The Python garbage collector (GC), which pauses attached threads during collection.

To avoid deadlocks in these cases, threads should take care to be detached from the Python interpreter before performing operations which might block waiting for other threads attached to the Python interpreter.

This module provides synchronization primitives which are able to synchronize under these conditions.

Structs§

GILOnceCellDeprecated
A write-once primitive similar to std::sync::OnceLock<T>.
GILProtectedDeprecated
Value with concurrent access protected by the GIL.
PyOnceLock
An equivalent to std::sync::OnceLock for initializing objects while attached to the Python interpreter.

Traits§

MutexExt
Extension trait for std::sync::Mutex which helps avoid deadlocks between the Python interpreter and acquiring the Mutex.
OnceExt
Extension trait for Once to help avoid deadlocking when using a Once when attached to a Python thread.
OnceLockExt
Extension trait for std::sync::OnceLock which helps avoid deadlocks between the Python interpreter and initialization with the OnceLock.
RwLockExt
Extension trait for std::sync::RwLock which helps avoid deadlocks between the Python interpreter and acquiring the RwLock.

Functions§

with_critical_section
Executes a closure with a Python critical section held on an object.
with_critical_section2
Executes a closure with a Python critical section held on two objects.