Mailing List Archive

gh-117657: Quiet TSAN warnings about remaining non-atomic accesses of `tstate->state` (#118165)
https://github.com/python/cpython/commit/2e7771a03d8975ee8a9918ce754c665508c3f682
commit: 2e7771a03d8975ee8a9918ce754c665508c3f682
branch: main
author: mpage <mpage@meta.com>
committer: DinoV <dinoviehland@gmail.com>
date: 2024-04-23T10:20:14-07:00
summary:

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`

files:
M Python/parking_lot.c
M Python/pystate.c

diff --git a/Python/parking_lot.c b/Python/parking_lot.c
index d5877fef56e4d0..b368b500ccdfdb 100644
--- a/Python/parking_lot.c
+++ b/Python/parking_lot.c
@@ -194,7 +194,8 @@ _PySemaphore_Wait(_PySemaphore *sema, PyTime_t timeout, int detach)
PyThreadState *tstate = NULL;
if (detach) {
tstate = _PyThreadState_GET();
- if (tstate && tstate->state == _Py_THREAD_ATTACHED) {
+ if (tstate && _Py_atomic_load_int_relaxed(&tstate->state) ==
+ _Py_THREAD_ATTACHED) {
// Only detach if we are attached
PyEval_ReleaseThread(tstate);
}
diff --git a/Python/pystate.c b/Python/pystate.c
index 06806bd75fbcb2..bca28cebcc9059 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -2096,7 +2096,7 @@ _PyThreadState_Suspend(PyThreadState *tstate)
{
_PyRuntimeState *runtime = &_PyRuntime;

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

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

_______________________________________________
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