https://github.com/python/cpython/commit/365cf5fc23835fa6dc8608396109085f31d2d5f0
commit: 365cf5fc23835fa6dc8608396109085f31d2d5f0
branch: main
author: Bogdan Romanyuk <[email protected]>
committer: colesbury <[email protected]>
date: 2025-02-06T15:35:37-05:00
summary:
gh-117657: Fix data race in `new_reference` for free threaded build (gh-129665)
files:
M Objects/object.c
M Tools/tsan/suppressions_free_threading.txt
diff --git a/Objects/object.c b/Objects/object.c
index fdff16138201a0..f3c7fa6d906ad6 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -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
diff --git a/Tools/tsan/suppressions_free_threading.txt
b/Tools/tsan/suppressions_free_threading.txt
index e5eb665ae212de..b25b3700b35613 100644
--- a/Tools/tsan/suppressions_free_threading.txt
+++ b/Tools/tsan/suppressions_free_threading.txt
@@ -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
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]