Skip to content

gh-117657: Fix data race in new_reference for free-threaded build #129665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2485,13 +2485,20 @@ new_reference(PyObject *op)
op->ob_refcnt = 1;
#endif
#else
op->ob_tid = _Py_ThreadId();
op->ob_flags = 0;
op->ob_mutex = (PyMutex){ 0 };
#ifdef _Py_THREAD_SANITIZER
_Py_atomic_store_uintptr_relaxed(&op->ob_tid, _Py_ThreadId());
_Py_atomic_store_uint8_relaxed(&op->ob_gc_bits, 0);
_Py_atomic_store_uint32_relaxed(&op->ob_ref_local, 1);
_Py_atomic_store_ssize_relaxed(&op->ob_ref_shared, 0);
#else
op->ob_tid = _Py_ThreadId();
op->ob_gc_bits = 0;
op->ob_ref_local = 1;
op->ob_ref_shared = 0;
#endif
#endif
#ifdef Py_TRACE_REFS
_Py_AddToAllObjects(op);
#endif
Expand Down
1 change: 0 additions & 1 deletion Tools/tsan/suppressions_free_threading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ race:free_threadstate
# These warnings trigger directly in a CPython function.

race_top:assign_version_tag
race_top:new_reference
race_top:_multiprocessing_SemLock_acquire_impl
race_top:list_get_item_ref
race_top:_Py_slot_tp_getattr_hook
Expand Down
Loading