From: Edward Xu Date: Mon, 3 Aug 2026 15:20:39 +0000 (+0800) Subject: gh-154937: Fix `_thread._shutdown()` racing with `_thread.start_joinable_thread`... X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a4095ee272f5e5082281a94a0856dde3c2f323f9;p=thirdparty%2FPython%2Fcpython.git gh-154937: Fix `_thread._shutdown()` racing with `_thread.start_joinable_thread` on `ThreadHandle.ident` (#155085) --- diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst new file mode 100644 index 000000000000..475dc8358a8d --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst @@ -0,0 +1,3 @@ +Fix a data race on thread handle identifiers when ``_thread._shutdown()`` +runs concurrently with the startup of non-daemon threads in the +:term:`free-threaded build`. diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index e999fe20287e..199e4ac3db72 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -2413,7 +2413,7 @@ thread_shutdown(PyObject *self, PyObject *args) struct llist_node *node; llist_for_each_safe(node, &state->shutdown_handles) { ThreadHandle *cur = llist_data(node, ThreadHandle, shutdown_node); - if (cur->ident != ident) { + if (ThreadHandle_ident(cur) != ident) { ThreadHandle_incref(cur); handle = cur; break;