Skip to content

Commit 2e7771a

Browse files
authored
gh-117657: Quiet TSAN warnings about remaining non-atomic accesses of tstate->state (#118165)
Quiet TSAN warnings about remaining non-atomic accesses of `tstate->state`
1 parent 0d221e9 commit 2e7771a

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Python/parking_lot.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ _PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout, int detach)
194194
PyThreadState *tstate = NULL;
195195
if (detach) {
196196
tstate = _PyThreadState_GET();
197-
if (tstate && tstate->state == _Py_THREAD_ATTACHED) {
197+
if (tstate && _Py_atomic_load_int_relaxed(&tstate->state) ==
198+
_Py_THREAD_ATTACHED) {
198199
// Only detach if we are attached
199200
PyEval_ReleaseThread(tstate);
200201
}

Python/pystate.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ _PyThreadState_Suspend(PyThreadState *tstate)
20962096
{
20972097
_PyRuntimeState *runtime = &_PyRuntime;
20982098

2099-
assert(tstate->state == _Py_THREAD_ATTACHED);
2099+
assert(_Py_atomic_load_int_relaxed(&tstate->state) == _Py_THREAD_ATTACHED);
21002100

21012101
struct _stoptheworld_state *stw = NULL;
21022102
HEAD_LOCK(runtime);

0 commit comments

Comments
 (0)