HEAD_LOCK is called from _PyEval_ReInitThreads->_PyThreadState_DeleteExcept before _PyRuntimeState_ReInitThreads reinit runtime->interpreters.mutex which might be locked before fork.
(cherry picked from commit
522799a05e3e820339718151ac055af6d864d463)
Co-authored-by: ChuBoning <102216855+ChuBoning@users.noreply.github.com>
--- /dev/null
+A deadlock involving ``pystate.c``'s ``HEAD_LOCK`` in ``posixmodule.c``
+at fork is now fixed. Patch by ChuBoning based on previous Python 3.12
+fix by Victor Stinner.
{
_PyRuntimeState *runtime = &_PyRuntime;
_PyGILState_Reinit(runtime);
+ _PyRuntimeState_ReInitThreads(runtime);
_PyEval_ReInitThreads(runtime);
_PyImport_ReInitLock();
_PySignal_AfterFork();
- _PyRuntimeState_ReInitThreads(runtime);
_PyInterpreterState_DeleteExceptMain(runtime);
run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);