-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Add a Per-Interpreter "HEAD" Lock #114940
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-subinterpreterstype-featureA feature request or enhancementA feature request or enhancement
Projects
Status
Todo
Feature or enhancement
We have a lock that we use for thread-safety when working with the set of interpreters:
_PyRuntimeState.interpreters.mutex. We use two macros in several core files to manage that lock:HEAD_LOCK()andHEAD_UNLOCK()(from pycore_pystate.h).Recently we've begun using that runtime-global lock for thread-safety when working with a single interpreter's set of thread states (
PyInterpreterState.threads). The problem is that this means we are potentially blocking interpreters unnecessarily.Thus it makes sense to introduce an interpreter-specific "head" lock:
PyInterpreterState.threads.mutex(plus corresponding macros).Linked PRs
PyInterpreterState.threads#125561