Skip to content

Commit

Permalink
Take profile lock after suspending thread
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 6, 2021
1 parent c75c7bb commit 71041f7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/signals-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@ static void *signal_listener(void *arg)
// sample each thread, round-robin style in reverse order
// (so that thread zero gets notified last)
if (critical || profile) {
jl_lock_profile();
if (!critical)
jl_shuffle_int_array_inplace(profile_round_robin_thread_order, jl_n_threads, &profile_cong_rng_seed);
for (int idx = jl_n_threads; idx-- > 0; ) {
Expand All @@ -759,6 +758,10 @@ static void *signal_listener(void *arg)
// notify thread to stop
jl_thread_suspend_and_get_state(i, &signal_context);

// Taking profile lock after to avoid deadlock in case the i-th thread is
// trying to take the lock when signalled.
jl_lock_profile();

// do backtrace on thread contexts for critical signals
// this part must be signal-handler safe
if (critical) {
Expand Down Expand Up @@ -810,10 +813,11 @@ static void *signal_listener(void *arg)
}
}

jl_unlock_profile();

// notify thread to resume
jl_thread_resume(i, sig);
}
jl_unlock_profile();
}
#ifndef HAVE_MACH
if (profile && running) {
Expand Down

0 comments on commit 71041f7

Please sign in to comment.