mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-117657: Fix data races when writing / reading ob_gc_bits
(#118292)
Use relaxed atomics when reading / writing to the field. There are still a few places in the GC where we do not use atomics. Those should be safe as the world is stopped.
This commit is contained in:
parent
8d84120b41
commit
cb6f75a32c
4 changed files with 45 additions and 16 deletions
|
@ -2427,6 +2427,7 @@ _PyObject_SetDeferredRefcount(PyObject *op)
|
|||
assert(PyType_IS_GC(Py_TYPE(op)));
|
||||
assert(_Py_IsOwnedByCurrentThread(op));
|
||||
assert(op->ob_ref_shared == 0);
|
||||
_PyObject_SET_GC_BITS(op, _PyGC_BITS_DEFERRED);
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
if (interp->gc.immortalize.enabled) {
|
||||
// gh-117696: immortalize objects instead of using deferred reference
|
||||
|
@ -2434,7 +2435,6 @@ _PyObject_SetDeferredRefcount(PyObject *op)
|
|||
_Py_SetImmortal(op);
|
||||
return;
|
||||
}
|
||||
op->ob_gc_bits |= _PyGC_BITS_DEFERRED;
|
||||
op->ob_ref_local += 1;
|
||||
op->ob_ref_shared = _Py_REF_QUEUED;
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue