From 4847114838cafa71681af300054c1d7219a92aa2 Mon Sep 17 00:00:00 2001 From: Edward Xu Date: Mon, 3 Aug 2026 23:20:39 +0800 Subject: [PATCH 1/2] gh-154937: Fix `_thread._shutdown()` racing with `_thread.start_joinable_thread` on `ThreadHandle.ident` (GH-155085) (cherry picked from commit a4095ee272f5e5082281a94a0856dde3c2f323f9) Co-authored-by: Edward Xu --- .../2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst | 3 +++ Modules/_threadmodule.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst 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 000000000000000..475dc8358a8d811 --- /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 bc9433afe41ef10..4ce32a8fa2fe0bc 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -2349,7 +2349,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; From 880702b87834764bc771a84ca272133c9c0fe464 Mon Sep 17 00:00:00 2001 From: "T. Wouters" Date: Tue, 4 Aug 2026 11:06:38 +0200 Subject: [PATCH 2/2] Remove free-threaded build as term from NEWS entry --- .../2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 475dc8358a8d811..e307b95216934aa 100644 --- 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 @@ -1,3 +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`. +free-threaded build.