Skip to content

Commit

Permalink
Wipe ptls->system_id when a thread exits.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maleadt committed Aug 1, 2023
1 parent ec8df3d commit 6a356f5
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 6a356f5

Please sign in to comment.