Skip to content

Commit 7cb877b

Browse files
committed
fix the race
1 parent 75b628a commit 7cb877b

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Objects/object.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2485,12 +2485,12 @@ new_reference(PyObject *op)
24852485
op->ob_refcnt = 1;
24862486
#endif
24872487
#else
2488-
op->ob_tid = _Py_ThreadId();
2488+
_Py_atomic_store_uintptr_relaxed(&op->ob_tid, _Py_ThreadId());
24892489
op->ob_flags = 0;
24902490
op->ob_mutex = (PyMutex){ 0 };
2491-
op->ob_gc_bits = 0;
2492-
op->ob_ref_local = 1;
2493-
op->ob_ref_shared = 0;
2491+
_Py_atomic_store_uint8_relaxed(&op->ob_gc_bits, 0);
2492+
_Py_atomic_store_uint32_relaxed(&op->ob_ref_local, 1);
2493+
_Py_atomic_store_ssize_relaxed(&op->ob_ref_shared, 0);
24942494
#endif
24952495
#ifdef Py_TRACE_REFS
24962496
_Py_AddToAllObjects(op);

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ race:free_threadstate
2222
# These warnings trigger directly in a CPython function.
2323

2424
race_top:assign_version_tag
25-
race_top:new_reference
2625
race_top:_multiprocessing_SemLock_acquire_impl
2726
race_top:list_get_item_ref
2827
race_top:_Py_slot_tp_getattr_hook

0 commit comments

Comments
 (0)