Skip to content

Commit

Permalink
[3.13] pythongh-117657: Fix TSAN race in QSBR assertion (pythonGH-119887
Browse files Browse the repository at this point in the history
) (python#119904)

Due to a limitation in TSAN, all reads from `PyThreadState.state` must be
atomic to avoid reported races.
(cherry picked from commit 90ec19f)

Co-authored-by: Sam Gross <[email protected]>
  • Loading branch information
miss-islington and colesbury authored Jun 1, 2024
1 parent 48f3378 commit 48054d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Python/qsbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ qsbr_poll_scan(struct _qsbr_shared *shared)
bool
_Py_qsbr_poll(struct _qsbr_thread_state *qsbr, uint64_t goal)
{
assert(_PyThreadState_GET()->state == _Py_THREAD_ATTACHED);
assert(_Py_atomic_load_int_relaxed(&_PyThreadState_GET()->state) == _Py_THREAD_ATTACHED);

if (_Py_qbsr_goal_reached(qsbr, goal)) {
return true;
}
Expand Down
2 changes: 0 additions & 2 deletions Tools/tsan/suppressions_free_threading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ race_top:_PyFrame_GetCode
race_top:_PyFrame_Initialize
race_top:PyInterpreterState_ThreadHead
race_top:_PyObject_TryGetInstanceAttribute
race_top:_Py_qsbr_unregister
race_top:_Py_qsbr_poll
race_top:PyThreadState_Next
race_top:Py_TYPE
race_top:PyUnstable_InterpreterFrame_GetLine
Expand Down

0 comments on commit 48054d2

Please sign in to comment.