Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
Feature or enhancement
Overview
ThePyMutex APIs are currently internal-only inpycore_lock.h. This proposes making the type and two functions public in as part of the general, non-limited API inInclude/cpython/lock.h.
The APIs to be included in the public header are:
typedefstructPyMutex {uint8_tv;}PyMutex;staticinlinevoidPyMutex_Lock(PyMutex*m) { ... }staticinlinevoidPyMutex_Unlock(PyMutex*m) { ... }// (private) slow path for locking the mutexPyAPI_FUNC(void)_PyMutex_LockSlow(PyMutex*m);// (private) slow path for unlocking the mutexPyAPI_FUNC(void)_PyMutex_UnlockSlow(PyMutex*m);
Motivation
- With the free-threaded build, C API extensions are more likely to require locking for thread-safety
- The
PyMutexAPI is easier to use correctly than the existingPyThread_type_lock. ThePyMutexAPIs release the GIL before blocking, whereas with thePyThread_type_lockAPIs you often want to use atwo step approach to locking to release the GIL before blocking. - The
PyMutexAPI enables a more efficient implementation: it's faster to acquire when the lock is not contended and does not require allocation.