Skip to content

Commit 90ec19f

Browse files
authored
gh-117657: Fix TSAN race in QSBR assertion (#119887)
Due to a limitation in TSAN, all reads from `PyThreadState.state` must be atomic to avoid reported races.
1 parent 60593b2 commit 90ec19f

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

Python/qsbr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ qsbr_poll_scan(struct _qsbr_shared *shared)
160160
bool
161161
_Py_qsbr_poll(struct _qsbr_thread_state *qsbr, uint64_t goal)
162162
{
163-
assert(_PyThreadState_GET()->state == _Py_THREAD_ATTACHED);
163+
assert(_Py_atomic_load_int_relaxed(&_PyThreadState_GET()->state) == _Py_THREAD_ATTACHED);
164+
164165
if (_Py_qbsr_goal_reached(qsbr, goal)) {
165166
return true;
166167
}

Tools/tsan/suppressions_free_threading.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ race_top:_PyFrame_GetCode
7575
race_top:_PyFrame_Initialize
7676
race_top:PyInterpreterState_ThreadHead
7777
race_top:_PyObject_TryGetInstanceAttribute
78-
race_top:_Py_qsbr_unregister
79-
race_top:_Py_qsbr_poll
8078
race_top:PyThreadState_Next
8179
race_top:Py_TYPE
8280
race_top:PyUnstable_InterpreterFrame_GetLine

0 commit comments

Comments
 (0)