Skip to content

Commit 9f983e0

Browse files
authored
gh-116515: Clear thread-local state before tstate_delete_common() (#116517)
This moves `current_fast_clear()` up so that the current thread state is `NULL` while running `tstate_delete_common()`. This doesn't fix any bugs, but it means that we are more consistent that `_PyThreadState_GET() != NULL` means that the thread is "attached".
1 parent 05070f4 commit 9f983e0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Python/pystate.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,7 @@ tstate_delete_common(PyThreadState *tstate)
16091609
{
16101610
assert(tstate->_status.cleared && !tstate->_status.finalized);
16111611
assert(tstate->state != _Py_THREAD_ATTACHED);
1612+
tstate_verify_not_active(tstate);
16121613

16131614
PyInterpreterState *interp = tstate->interp;
16141615
if (interp == NULL) {
@@ -1687,8 +1688,8 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
16871688
_Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
16881689
#endif
16891690
tstate_set_detached(tstate, _Py_THREAD_DETACHED);
1690-
tstate_delete_common(tstate);
16911691
current_fast_clear(tstate->interp->runtime);
1692+
tstate_delete_common(tstate);
16921693
_PyEval_ReleaseLock(tstate->interp, NULL);
16931694
free_threadstate((_PyThreadStateImpl *)tstate);
16941695
}

0 commit comments

Comments
 (0)