From 6a356f55fb8c97f0663356670375b03999bc8f21 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Tue, 1 Aug 2023 16:34:54 +0200 Subject: [PATCH] Wipe ptls->system_id when a thread exits. On macOS, we use the system thread ID to match against the list of known thread local states during signal handling. To prevent picking up the wrong entry, i.e. from when a thread was previously executing a different task, make sure to wipe the system ID when a thread exits. This manifested as the signal handler actually reporting a bus error when a thread touched safepoint memory during GC, because the matched thread local state had no current task attached to it. Fixes JuliaGPU/Metal.jl#225 --- src/threading.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/threading.c b/src/threading.c index e2eb686e3061a..f956e46bb9b0b 100644 --- a/src/threading.c +++ b/src/threading.c @@ -474,6 +474,7 @@ static void jl_delete_thread(void *value) JL_NOTSAFEPOINT_ENTER abort(); } jl_atomic_store_relaxed(&ptls->current_task, NULL); // dead + ptls->system_id = 0; // finally, release all of the locks we had grabbed #ifdef _OS_WINDOWS_ jl_unlock_profile_wr();