From 0009ed864960b5b45d9f6492827af52c2dddf9f3 Mon Sep 17 00:00:00 2001 From: Jason Fried Date: Mon, 22 May 2017 16:58:55 -0700 Subject: [PATCH] [3.6] bpo-30395 _PyGILState_Reinit deadlock fix (GH-1734) head_lock could be held by another thread when fork happened. We should reset it to avoid deadlock. (cherry picked from commit f82c951d1c5416f3550d544e50ff5662d3836e73) --- Misc/ACKS | 1 + Python/pystate.c | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Misc/ACKS b/Misc/ACKS index 7109ccbe851384..b8bac248d98867 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -552,6 +552,7 @@ Eric Groo Daniel Andrade Groppe Dag Gruneau Filip GruszczyƄski +Andrii Grynenko Grzegorz Grzywacz Thomas Guettler Yuyang Guo diff --git a/Python/pystate.c b/Python/pystate.c index 65c244e6f73617..ccb0092c42b3a4 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -743,6 +743,10 @@ _PyGILState_Fini(void) void _PyGILState_Reinit(void) { +#ifdef WITH_THREAD + head_mutex = NULL; + HEAD_INIT(); +#endif PyThreadState *tstate = PyGILState_GetThisThreadState(); PyThread_delete_key(autoTLSkey); if ((autoTLSkey = PyThread_create_key()) == -1)