]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117657: Fix race data race in `_Py_IsOwnedByCurrentThread()` (#118258)
authormpage <mpage@meta.com>
Fri, 26 Apr 2024 14:39:08 +0000 (07:39 -0700)
committerGitHub <noreply@github.com>
Fri, 26 Apr 2024 14:39:08 +0000 (10:39 -0400)
Include/object.h
Tools/tsan/suppressions_free_threading.txt

index 5aaf11c5194f0e3f1eb1d1396c36bd66548d1554..9132784628a5018dd8a02b69f718eefce6dd19b0 100644 (file)
@@ -303,7 +303,11 @@ _Py_ThreadId(void)
 static inline Py_ALWAYS_INLINE int
 _Py_IsOwnedByCurrentThread(PyObject *ob)
 {
+#ifdef _Py_THREAD_SANITIZER
+    return _Py_atomic_load_uintptr_relaxed(&ob->ob_tid) == _Py_ThreadId();
+#else
     return ob->ob_tid == _Py_ThreadId();
+#endif
 }
 #endif
 
index e4ca32bebc5a22be4cda6b040f71883a3961ca63..4b1a2fdf6dd43aa09129cbcbd2bda3b7ad17c647 100644 (file)
@@ -14,7 +14,6 @@ race:set_allocator_unlocked
 race:_add_to_weak_set
 race:_in_weak_set
 race:_mi_heap_delayed_free_partial
-race:_Py_IsOwnedByCurrentThread
 race:_PyEval_EvalFrameDefault
 race:_PyFunction_SetVersion
 race:_PyImport_AcquireLock