You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PEP 703 introduces the concept of "Python Critical Sections", which are an abstraction to help replace the GIL with finer grained locking. The key ideas is to replace the GIL with per-object locks and implicitly release these locks in the same places where the GIL would have been released. The mechanism is:
Keep track of locked mutexes in a per-thread stack
These will be no-ops in the default build of CPython.
Note that if you need to operate on two objects at once, then you must use the Py_BEGIN_CRITICAL_SECTION2 macro. Nesting two calls to Py_BEGIN_CRITICAL_SECTION does not guarantee that both objects are locked because the inner calls may suspend the outer critical section.
At least at the start, even these "public" macros will still be internal-only (i.e., in Include/internal). I expect that we will eventually want to make them public so that C-API extensions can make use of them. ↩
Feature or enhancement
PEP 703 introduces the concept of "Python Critical Sections", which are an abstraction to help replace the GIL with finer grained locking. The key ideas is to replace the GIL with per-object locks and implicitly release these locks in the same places where the GIL would have been released. The mechanism is:
_PyThreadState_Detach()), unlock all of the thread's locked mutexesThe "public" 1 API consists of four macros:
These will be no-ops in the default build of CPython.
Note that if you need to operate on two objects at once, then you must use the
Py_BEGIN_CRITICAL_SECTION2macro. Nesting two calls toPy_BEGIN_CRITICAL_SECTIONdoes not guarantee that both objects are locked because the inner calls may suspend the outer critical section.Linked PRs
Footnotes
At least at the start, even these "public" macros will still be internal-only (i.e., in
Include/internal). I expect that we will eventually want to make them public so that C-API extensions can make use of them. ↩