Feature or enhancement
In general, when _PyThreadState_GET() is non-NULL then the current thread is "attached", but there is a small window during PyThreadState_DeleteCurrent() where that's not true: tstate_delete_common() is called when the thread is detached, but before current_fast_clear():
|
tstate_set_detached(tstate, _Py_THREAD_DETACHED); |
|
tstate_delete_common(tstate); |
|
current_fast_clear(tstate->interp->runtime); |
I think it's worth swapping the order of the calls so that we call current_fast_clear before tstate_delete_common. This would also make the order of operations in PyThreadState_DeleteCurrent() more similar to the order used when calling PyThreadState_Delete().
See also: #116483
cc @ericsnowcurrently
Linked PRs
Feature or enhancement
In general, when
_PyThreadState_GET()is non-NULL then the current thread is "attached", but there is a small window duringPyThreadState_DeleteCurrent()where that's not true: tstate_delete_common() is called when the thread is detached, but before current_fast_clear():cpython/Python/pystate.c
Lines 1689 to 1691 in 601f3a7
I think it's worth swapping the order of the calls so that we call
current_fast_clearbeforetstate_delete_common. This would also make the order of operations inPyThreadState_DeleteCurrent()more similar to the order used when callingPyThreadState_Delete().See also: #116483
cc @ericsnowcurrently
Linked PRs