]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-96387: take_gil() resets drop request before exit (#96869) (#96941)
authorVictor Stinner <vstinner@python.org>
Tue, 20 Sep 2022 00:12:09 +0000 (02:12 +0200)
committerGitHub <noreply@github.com>
Tue, 20 Sep 2022 00:12:09 +0000 (02:12 +0200)
commit6ff54716f1073a4bcfed8a1ec0b518c489c1af0d
tree6f6603f463e8d9cf59223c61682cd86817e56ff6
parente0d6cc83169d9a363b263e16ddc3a57facc7a704
gh-96387: take_gil() resets drop request before exit (#96869) (#96941)

At Python exit, sometimes a thread holding the GIL can wait forever
for a thread (usually a daemon thread) which requested to drop the
GIL, whereas the thread already exited. To fix the race condition,
the thread which requested the GIL drop now resets its request before
exiting.

take_gil() now calls RESET_GIL_DROP_REQUEST() before
PyThread_exit_thread() if it called SET_GIL_DROP_REQUEST to fix a
race condition with drop_gil().

Issue discovered and analyzed by Mingliang ZHAO.

(cherry picked from commit 04f4977f508583954ad7b9cb09076ee1e57461f8)
Misc/NEWS.d/next/Core and Builtins/2022-09-16-16-54-35.gh-issue-96387.GRzewg.rst [new file with mode: 0644]
Python/ceval_gil.h