-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make the MRO cache thread-safe in free-threaded builds #113743
Labels
3.13
bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-feature
A feature request or enhancement
Comments
colesbury
added
type-feature
A feature request or enhancement
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
3.13
bugs and security fixes
topic-free-threading
labels
Jan 5, 2024
DinoV
added a commit
that referenced
this issue
Feb 15, 2024
…13930) Makes _PyType_Lookup thread safe, including: Thread safety of the underlying cache. Make mutation of mro and type members thread safe Also _PyType_GetMRO and _PyType_GetBases are currently returning borrowed references which aren't safe.
DinoV
added a commit
that referenced
this issue
Feb 16, 2024
Move type-lock to per-interpreter lock to avoid heavy contention in interpreters test
benjaminp
added a commit
to benjaminp/cpython
that referenced
this issue
Feb 16, 2024
Fixes a compiler warning.
woodruffw
pushed a commit
to woodruffw-forks/cpython
that referenced
this issue
Mar 4, 2024
Fixes a compiler warning.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
…ds (python#113930) Makes _PyType_Lookup thread safe, including: Thread safety of the underlying cache. Make mutation of mro and type members thread safe Also _PyType_GetMRO and _PyType_GetBases are currently returning borrowed references which aren't safe.
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
Move type-lock to per-interpreter lock to avoid heavy contention in interpreters test
diegorusso
pushed a commit
to diegorusso/cpython
that referenced
this issue
Apr 17, 2024
Fixes a compiler warning.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
3.13
bugs and security fixes
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-free-threading
type-feature
A feature request or enhancement
Feature or enhancement
The MRO (method resolution order) cache is used to cache lookups on the type hierarchy, such as method lookups. It's currently implemented per-interpreter, which will not be thread-safe in free-threaded builds.
cpython/Objects/typeobject.c
Lines 4750 to 4803 in 5e1916b
The nogil-3.9 and nogil-3.12 forks used different approaches to make the MRO cache thread-safe. The nogil-3.9 fork moved the type cache to the
PyThreadState
. The nogil-3.12 fork implemented a thread-safe cache shared across threads 1. The nogil-3.9 approach is much simpler, I think we should start with that.Suggested approach:
Py_GIL_DISABLED
is defined, move the type_cache to the private structPyThreadStateImpl
._PyType_Lookup()
as necessary to use the correct cacheLinked PRs
Footnotes
For reference, here is the nogil-3.12 implementation: https://github.com/colesbury/nogil-3.12/commit/9c1f7ba1b4 ↩
The text was updated successfully, but these errors were encountered: