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 weakref thread-safe without the GIL #111926
Comments
Maybe we should check the performance impact the default build first. |
The critical section APIs are no-ops on the default build: cpython/Include/internal/pycore_critical_section.h Lines 107 to 113 in 289af86
|
I know that there is no op for the default build but the commit you suggested modify some internal structure, I just want to know ovehead from the structure changed, even I actually do not expect real overhead from some refactoring. (I didn't look at deeply now please let me know if I miss something) |
@corona10 the commit I linked to (in nogil-3.12) is not how I intend to make weakref thread-safe in CPython 3.13. I wouldn't spend too much time investigating it because it's not going to make it's way into 3.13. I linked to it because it's sometimes helpful for me to look back at the nogil-3.12 implementation. |
By the way, I am working on it :) |
…h-113621) --------- Co-authored-by: Sam Gross <colesbury@gmail.com>
Is there more work to be done here? If yes, could you add a list of actionable items? |
I am still checking for the weakrefobject.c :) |
Feature or enhancement
The current weakref implementation relies on the GIL for thread-safety.
The
nogil-3.12
fork substantially modifies the weakref implementation. I think we can implement a simpler change in CPython 3.13 (main) now that all PyObject's have their own mutex (in--disable-gil
builds).Basic idea
Protect access to the weakrefs linked list using the mutex in the weakly referenced object. Use the critical section API.
Prior implementation: colesbury/nogil-3.12@0dddcb6f9d
Linked PRs
The text was updated successfully, but these errors were encountered: