Uh oh!
There was an error while loading. Please reload this page.
gh-111926: Make weakrefs thread-safe in free-threaded builds - #117168
Conversation
We need to tag weakrefs and their referents
The `is_dead` check from the default build is insufficient, since the refcount may go to zero between when we check and when we incref. More generally, `Py_NewRef` is unsafe to use if you have a borrowed refernce.
Locking is handled in the implementation
mpage
commented
Mar 29, 2024
@colesbury - Would you take another look at this when you get a chance, please? |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
bedevere-bot
commented
Apr 1, 2024
🤖 New build scheduled with the buildbot fleet by @colesbury for commit fece88d 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
We cannot assert now that we clear weakrefs without holding the lock in _PyStaticType_ClearWeakRefs
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
bedevere-bot
commented
Apr 8, 2024
🤖 New build scheduled with the buildbot fleet by @colesbury for commit 73466bf 🤖 If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
…ython#117168) Most mutable data is protected by a striped lock that is keyed on the referenced object's address. The weakref's hash is protected using the weakref's per-object lock. Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by `ifdef`s or is a no-op (e.g. `Py_BEGIN_CRITICAL_SECTION`).
hugovk
commented
Apr 26, 2024
I've started seeing a test failure that bisects to this PR. Please see issue #118331. |
This makes weakrefs thread-safe in free-threaded builds. Please see the comment at the beginning of
Objects/weakrefobject.cfor an explanation of the approach.Note that this only affects free-threaded builds. Apart from some minor refactoring, the added code is all either gated by
ifdefs or is a no-op (e.g.Py_BEGIN_CRITICAL_SECTION).