summaryrefslogtreecommitdiffstats
path: root/Python/ceval_gil.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/ceval_gil.c')
-rw-r--r--Python/ceval_gil.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c
index a679086..fd737b5 100644
--- a/Python/ceval_gil.c
+++ b/Python/ceval_gil.c
@@ -369,6 +369,7 @@ take_gil(PyThreadState *tstate)
goto _ready;
}
+ int drop_requested = 0;
while (_Py_atomic_load_relaxed(&gil->locked)) {
unsigned long saved_switchnum = gil->switch_number;
@@ -384,11 +385,21 @@ take_gil(PyThreadState *tstate)
{
if (tstate_must_exit(tstate)) {
MUTEX_UNLOCK(gil->mutex);
+ // gh-96387: If the loop requested a drop request in a previous
+ // iteration, reset the request. Otherwise, drop_gil() can
+ // block forever waiting for the thread which exited. Drop
+ // requests made by other threads are also reset: these threads
+ // may have to request again a drop request (iterate one more
+ // time).
+ if (drop_requested) {
+ RESET_GIL_DROP_REQUEST(interp);
+ }
PyThread_exit_thread();
}
assert(is_tstate_valid(tstate));
SET_GIL_DROP_REQUEST(interp);
+ drop_requested = 1;
}
}