mirror of https://github.com/python/cpython
gh-117303: Don't detach in `PyThreadState_DeleteCurrent()` (#117304)
This fixes a crash in `test_threading.test_reinit_tls_after_fork()` when running with the GIL disabled. We already properly handle the case where the thread state is `_Py_THREAD_ATTACHED` in `tstate_delete_common()` -- we just need to remove an assertion. Keeping the thread attached means that a stop-the-world pause, such as for a `fork()`, won't commence until we remove our thread state from the interpreter's linked list. This prevents a crash when the child process tries to clean up the dead thread states.
This commit is contained in:
parent
05e0b67a43
commit
bfc57d43d8
|
@ -1660,7 +1660,6 @@ static void
|
||||||
tstate_delete_common(PyThreadState *tstate)
|
tstate_delete_common(PyThreadState *tstate)
|
||||||
{
|
{
|
||||||
assert(tstate->_status.cleared && !tstate->_status.finalized);
|
assert(tstate->_status.cleared && !tstate->_status.finalized);
|
||||||
assert(tstate->state != _Py_THREAD_ATTACHED);
|
|
||||||
tstate_verify_not_active(tstate);
|
tstate_verify_not_active(tstate);
|
||||||
assert(!_PyThreadState_IsRunningMain(tstate));
|
assert(!_PyThreadState_IsRunningMain(tstate));
|
||||||
|
|
||||||
|
@ -1740,7 +1739,6 @@ _PyThreadState_DeleteCurrent(PyThreadState *tstate)
|
||||||
#ifdef Py_GIL_DISABLED
|
#ifdef Py_GIL_DISABLED
|
||||||
_Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
|
_Py_qsbr_detach(((_PyThreadStateImpl *)tstate)->qsbr);
|
||||||
#endif
|
#endif
|
||||||
tstate_set_detached(tstate, _Py_THREAD_DETACHED);
|
|
||||||
current_fast_clear(tstate->interp->runtime);
|
current_fast_clear(tstate->interp->runtime);
|
||||||
tstate_delete_common(tstate);
|
tstate_delete_common(tstate);
|
||||||
_PyEval_ReleaseLock(tstate->interp, NULL);
|
_PyEval_ReleaseLock(tstate->interp, NULL);
|
||||||
|
|
Loading…
Reference in New Issue