Mailing List Archive

gh-117657: Fix race data race in `_Py_IsOwnedByCurrentThread()` (#118258)
https://github.com/python/cpython/commit/a5eeb832c2bbbd6ce1e9d545a553de926af468d5
commit: a5eeb832c2bbbd6ce1e9d545a553de926af468d5
branch: main
author: mpage <mpage@meta.com>
committer: colesbury <colesbury@gmail.com>
date: 2024-04-26T10:39:08-04:00
summary:

gh-117657: Fix race data race in `_Py_IsOwnedByCurrentThread()` (#118258)

files:
M Include/object.h
M Tools/tsan/suppressions_free_threading.txt

diff --git a/Include/object.h b/Include/object.h
index 5aaf11c5194f0e..9132784628a501 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -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

diff --git a/Tools/tsan/suppressions_free_threading.txt b/Tools/tsan/suppressions_free_threading.txt
index e4ca32bebc5a22..4b1a2fdf6dd43a 100644
--- a/Tools/tsan/suppressions_free_threading.txt
+++ b/Tools/tsan/suppressions_free_threading.txt
@@ -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

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com