@@ -1398,9 +1398,22 @@ JL_DLLEXPORT void jl_print_backtrace(void) JL_NOTSAFEPOINT
13981398 jlbacktrace ();
13991399}
14001400
1401- // Print backtraces for all live tasks, for all threads, to jl_safe_printf stderr
1401+ extern int jl_inside_heartbeat_thread (void );
1402+ extern int jl_heartbeat_pause (void );
1403+ extern int jl_heartbeat_resume (void );
1404+
1405+ // Print backtraces for all live tasks, for all threads, to jl_safe_printf
1406+ // stderr. This can take a _long_ time!
14021407JL_DLLEXPORT void jl_print_task_backtraces (int show_done ) JL_NOTSAFEPOINT
14031408{
1409+ // disable heartbeats to prevent heartbeat loss while running this,
1410+ // unless this is called from the heartbeat thread itself; in that
1411+ // situation, the thread is busy running this and it will not be
1412+ // updating the missed heartbeats counter
1413+ if (!jl_inside_heartbeat_thread ()) {
1414+ jl_heartbeat_pause ();
1415+ }
1416+
14041417 size_t nthreads = jl_atomic_load_acquire (& jl_n_threads );
14051418 jl_ptls_t * allstates = jl_atomic_load_relaxed (& jl_all_tls_states );
14061419 int ctid = jl_threadid () + 1 ;
@@ -1459,6 +1472,10 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
14591472 jl_safe_printf ("thread (%d) ==== End thread %d\n" , ctid , ptls2 -> tid + 1 );
14601473 }
14611474 jl_safe_printf ("thread (%d) ++++ Done\n" , ctid );
1475+
1476+ if (!jl_inside_heartbeat_thread ()) {
1477+ jl_heartbeat_resume ();
1478+ }
14621479}
14631480
14641481#ifdef __cplusplus
0 commit comments