@@ -1410,9 +1410,22 @@ JL_DLLEXPORT void jl_print_backtrace(void) JL_NOTSAFEPOINT
14101410 jlbacktrace ();
14111411}
14121412
1413- // Print backtraces for all live tasks, for all threads, to jl_safe_printf stderr
1413+ extern int jl_inside_heartbeat_thread (void );
1414+ extern int jl_heartbeat_pause (void );
1415+ extern int jl_heartbeat_resume (void );
1416+
1417+ // Print backtraces for all live tasks, for all threads, to jl_safe_printf
1418+ // stderr. This can take a _long_ time!
14141419JL_DLLEXPORT void jl_print_task_backtraces (int show_done ) JL_NOTSAFEPOINT
14151420{
1421+ // disable heartbeats to prevent heartbeat loss while running this,
1422+ // unless this is called from the heartbeat thread itself; in that
1423+ // situation, the thread is busy running this and it will not be
1424+ // updating the missed heartbeats counter
1425+ if (!jl_inside_heartbeat_thread ()) {
1426+ jl_heartbeat_pause ();
1427+ }
1428+
14161429 size_t nthreads = jl_atomic_load_acquire (& jl_n_threads );
14171430 jl_ptls_t * allstates = jl_atomic_load_relaxed (& jl_all_tls_states );
14181431 int ctid = jl_threadid () + 1 ;
@@ -1471,6 +1484,10 @@ JL_DLLEXPORT void jl_print_task_backtraces(int show_done) JL_NOTSAFEPOINT
14711484 jl_safe_printf ("thread (%d) ==== End thread %d\n" , ctid , ptls2 -> tid + 1 );
14721485 }
14731486 jl_safe_printf ("thread (%d) ++++ Done\n" , ctid );
1487+
1488+ if (!jl_inside_heartbeat_thread ()) {
1489+ jl_heartbeat_resume ();
1490+ }
14741491}
14751492
14761493#ifdef __cplusplus
0 commit comments