diff --git a/Python/pystate.c b/Python/pystate.c index acec905484c21f..557450c6dfd09e 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -2003,7 +2003,7 @@ tstate_try_attach(PyThreadState *tstate) static void tstate_set_detached(PyThreadState *tstate, int detached_state) { - assert(tstate->state == _Py_THREAD_ATTACHED); + assert(_Py_atomic_load_int_relaxed(&tstate->state) == _Py_THREAD_ATTACHED); #ifdef Py_GIL_DISABLED _Py_atomic_store_int(&tstate->state, detached_state); #else @@ -2068,7 +2068,7 @@ static void detach_thread(PyThreadState *tstate, int detached_state) { // XXX assert(tstate_is_alive(tstate) && tstate_is_bound(tstate)); - assert(tstate->state == _Py_THREAD_ATTACHED); + assert(_Py_atomic_load_int_relaxed(&tstate->state) == _Py_THREAD_ATTACHED); assert(tstate == current_fast_get()); if (tstate->critical_section != 0) { _PyCriticalSection_SuspendAll(tstate);