handle threads stopping while trying to get a stack trace

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2018-09-10 12:24:52 +08:00 committed by eboasson
parent 30fe3dc803
commit feb5ba647e

View file

@ -285,15 +285,20 @@ void log_stacktrace (const char *name, os_threadId tid)
os_nanoSleep (d);
sigaction (SIGXCPU, &act, &oact);
pthread_kill (tid.v, SIGXCPU);
while (!os_atomic_cas32 (&log_stacktrace_flag, 2, 3))
while (!os_atomic_cas32 (&log_stacktrace_flag, 2, 3) && pthread_kill (tid.v, 0) == 0)
os_nanoSleep (d);
sigaction (SIGXCPU, &oact, NULL);
if (pthread_kill (tid.v, 0) != 0)
nn_log (~0u, "-- thread exited --\n");
else
{
nn_log (~0u, "-- stack trace follows --\n");
strs = backtrace_symbols (log_stacktrace_stk.stk, log_stacktrace_stk.depth);
for (i = 0; i < log_stacktrace_stk.depth; i++)
nn_log (~0u, "%s\n", strs[i]);
free (strs);
nn_log (~0u, "-- end of stack trace --\n");
}
os_atomic_st32 (&log_stacktrace_flag, 0);
}
}