| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
In the free-threaded build, _PyWeakref_GET_REF() no longer takes the striped weakref list lock. The referent's memory stays readable if it is freed concurrently because object heaps delay page reuse with QSBR, and wr_object only ever transitions from the referent to Py_None, so _Py_TryIncrefCompare() is sufficient. clear_weakref_lock_held() now uses release stores instead of sequentially consistent stores. The weakref list lock orders the list updates, and the lock-free read only requires that the store of Py_None happens before the referent's memory can be reused.
This block is GIL-enabled build only.
…free-weakref-get-ref
Even in the GIL-enabled build, the target's refcount can be zero here. Add a unit test that shows this and revert back to _Py_TryIncref.
| Back | FazBrowse Home | New Git URL |
In the free-threaded build, change _PyWeakref_GET_REF() so it no longer takes the striped weakref list lock. The referent's memory stays readable if it is freed concurrently because object heaps delay page reuse with QSBR, and wr_object only ever transitions from the referent to Py_None, so _Py_TryIncrefCompare() is sufficient.
Use release store for clear_weakref_lock_held(), instead of sequentially consistent stores. The weakref list lock orders the list updates, and the lock-free read only requires that the store of Py_None happens before the referent's memory can be reused.
The benchmark results below are based on a C extension implementing a weak-map using either PyUnstable_TryIncRef() (borrowed refereces) vs using weak references. Thread scaling of "get, N threads, private maps" (ns per op, lower is better):