Skip to content

Commit 64c0baf

Browse files
committed
Take profile lock after suspending thread in macOS as well
1 parent d9cff60 commit 64c0baf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/signals-mach.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,6 @@ void *mach_profile_listener(void *arg)
537537
HANDLE_MACH_ERROR("mach_msg", ret);
538538
// sample each thread, round-robin style in reverse order
539539
// (so that thread zero gets notified last)
540-
jl_lock_profile();
541540
void *unused = NULL;
542541
int keymgr_locked = _keymgr_get_and_lock_processwide_ptr_2(KEYMGR_GCC3_DW2_OBJ_LIST, &unused) == 0;
543542
jl_shuffle_int_array_inplace(profile_round_robin_thread_order, jl_n_threads, &profile_cong_rng_seed);
@@ -554,6 +553,10 @@ void *mach_profile_listener(void *arg)
554553
jl_thread_suspend_and_get_state2(i, &state);
555554
unw_context_t *uc = (unw_context_t*)&state;
556555

556+
// Taking profile lock after to avoid deadlock in case the i-th thread is
557+
// trying to take the lock when signalled.
558+
jl_lock_profile();
559+
557560
if (running) {
558561
#ifdef LLVMLIBUNWIND
559562
/*
@@ -606,12 +609,12 @@ void *mach_profile_listener(void *arg)
606609
bt_data_prof[bt_size_cur++].uintptr = 0;
607610
bt_data_prof[bt_size_cur++].uintptr = 0;
608611
}
612+
jl_unlock_profile();
609613
// We're done! Resume the thread.
610614
jl_thread_resume(i, 0);
611615
}
612616
if (keymgr_locked)
613617
_keymgr_unlock_processwide_ptr(KEYMGR_GCC3_DW2_OBJ_LIST);
614-
jl_unlock_profile();
615618
if (running) {
616619
// Reset the alarm
617620
kern_return_t ret = clock_alarm(clk, TIME_RELATIVE, timerprof, profile_port);

0 commit comments

Comments
 (0)