]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154937: Fix `_thread._shutdown()` racing with `_thread.start_joinable_thread`...
authorEdward Xu <xuxiangad@gmail.com>
Mon, 3 Aug 2026 15:20:39 +0000 (23:20 +0800)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2026 15:20:39 +0000 (15:20 +0000)
Misc/NEWS.d/next/Core_and_Builtins/2026-08-02-17-55-29.gh-issue-154937.m9IBba.rst [new file with mode: 0644]
Modules/_threadmodule.c

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 (file)
index 0000000..475dc83
--- /dev/null
@@ -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`.
index e999fe20287e2d6ef6d08cc94100cab06ca9b4b1..199e4ac3db723bf9586d557772e8c60ec018b8bd 100644 (file)
@@ -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;