@@ -1402,9 +1402,22 @@ JL_DLLEXPORT void jl_print_backtrace(void) JL_NOTSAFEPOINT
14021402 jlbacktrace ();
14031403}
14041404
1405- // Print backtraces for all live tasks, for all threads, to jl_safe_printf stderr
1405+ extern int jl_inside_heartbeat_thread (void );
1406+ extern int jl_heartbeat_pause (void );
1407+ extern int jl_heartbeat_resume (void );
1408+
1409+ // Print backtraces for all live tasks, for all threads, to jl_safe_printf
1410+ // stderr. This can take a _long_ time!
14061411JL_DLLEXPORT void jl_print_task_backtraces (int show_done ) JL_NOTSAFEPOINT
14071412{
1413+ // disable heartbeats to prevent heartbeat loss while running this,
1414+ // unless this is called from the heartbeat thread itself; in that
1415+ // situation, the thread is busy running this and it will not be
1416+ // updating the missed heartbeats counter
1417+ if (!jl_inside_heartbeat_thread ()) {
1418+ jl_heartbeat_pause ();
1419+ }
1420+
14081421 size_t nthreads = jl_atomic_load_acquire (& jl_n_threads );
14091422 jl_ptls_t * allstates = jl_atomic_load_relaxed (& jl_all_tls_states );
14101423 int ctid = jl_threadid () + 1 ;
@@ -1463,6 +1476,10 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
14631476 jl_safe_printf ("thread (%d) ==== End thread %d\n" , ctid , ptls2 -> tid + 1 );
14641477 }
14651478 jl_safe_printf ("thread (%d) ++++ Done\n" , ctid );
1479+
1480+ if (!jl_inside_heartbeat_thread ()) {
1481+ jl_heartbeat_resume ();
1482+ }
14661483}
14671484
14681485#ifdef __cplusplus
0 commit comments