From 37ca3f987deb20dfbf8584b4a8b8ac63cc20022a Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Thu, 10 Aug 2023 13:07:58 +0200 Subject: [PATCH] Fix data race. --- src/signals-mach.c | 3 +-- src/threading.c | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/signals-mach.c b/src/signals-mach.c index ae99d2f2ac0e8..652e2a03fca4d 100644 --- a/src/signals-mach.c +++ b/src/signals-mach.c @@ -385,12 +385,11 @@ static int jl_thread_suspend_and_get_state2(int tid, host_thread_state_t *ctx) jl_ptls_t ptls2 = jl_atomic_load_relaxed(&jl_all_tls_states)[tid]; if (ptls2 == NULL) // this thread is not alive return 0; + mach_port_t thread = pthread_mach_thread_np(jl_atomic_load_acquire(&ptls2->system_id)); jl_task_t *ct2 = ptls2 ? jl_atomic_load_relaxed(&ptls2->current_task) : NULL; if (ct2 == NULL) // this thread is already dead return 0; - mach_port_t thread = pthread_mach_thread_np(jl_atomic_load_relaxed(&ptls2->system_id)); - kern_return_t ret = thread_suspend(thread); HANDLE_MACH_ERROR("thread_suspend", ret); diff --git a/src/threading.c b/src/threading.c index 6a589f3841594..9077cf7215a0d 100644 --- a/src/threading.c +++ b/src/threading.c @@ -475,7 +475,7 @@ static void jl_delete_thread(void *value) JL_NOTSAFEPOINT_ENTER } // mark this thread as dead jl_atomic_store_relaxed(&ptls->current_task, NULL); - jl_atomic_store_relaxed(&ptls->system_id, 0); + jl_atomic_store_release(&ptls->system_id, 0); // finally, release all of the locks we had grabbed #ifdef _OS_WINDOWS_ jl_unlock_profile_wr();