Closed
Description
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
- gh-111926: Update _weakref to be threadsafe in --disable-gil build #112189
- gh-111926: Update _PyWeakref_IS_DEAD to be thread-safe #112267
- gh-111926: Set up basic sementics of weakref API for freethreading #113621
- gh-111926: Simplify weakref/proxy creation #116825
- gh-111926: Simplify weakref creation logic #116843
- gh-111926: Simplify proxy creation logic #116844
- gh-111926: Make weakrefs thread-safe in free-threaded builds #117168
- gh-111926: Avoid locking in PyType_IsSubtype #117275