Skip to content

Commit c309c66

Browse files
committed
Quiet TSAN warnings about remaining non-atomic accesses of tstate->state
These should be the last instances of TSAN warning of data races when accessing `tstate->state` non-atomically. TSAN reports a race between accessing `tstate->state` in `_PyThreadState_Suspend()` and the compare/exhange in `park_detached_threads`. This is a false positive due to TSAN modeling failed compare/exchange operations as writes. TSAN reports a race between accessing `tstate->state` in `_PySemaphore_Wait()` and the compare/exchange in `park_detached_threads`. This is the same issue that we saw in pythongh-117830.
1 parent fc21c7f commit c309c66

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

Python/parking_lot.c

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy