]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-96387: take_gil() resets drop request before exit (#96869)
authorVictor Stinner <vstinner@python.org>
Mon, 19 Sep 2022 22:13:56 +0000 (00:13 +0200)
committerGitHub <noreply@github.com>
Mon, 19 Sep 2022 22:13:56 +0000 (00:13 +0200)
commit04f4977f508583954ad7b9cb09076ee1e57461f8
tree4724eb64e88a0f65d9b978d3a42e5dd1c7cfd560
parentc10e33ac119d96c4d88d5ae8b59e65a76ae0ad3c
gh-96387: take_gil() resets drop request before exit (#96869)

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.
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.c