This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Description
The GetStackTrace implementation uses a global atomic to prevent multiple threads from calling into libunwind at the same time:
if (sync_val_compare_and_swap(&g_now_entering, false, true)) {
return 0;
}
The comment, however, says that the issue it's trying to protect from is reentrancy bugs, not concurrency:
// Sometimes, we can try to get a stack trace from within a stack
// trace, because libunwind can call mmap (maybe indirectly via an
// internal mmap based memory allocator), and that mmap gets trapped
// and causes a stack-trace request. If were to try to honor that
// recursive request, we'd end up with infinite recursion or deadlock.
// Luckily, it's safe to ignore those subsequent traces. In such
// cases, we return 0 to indicate the situation.
Given this, it makes more sense for the flag to be a threadlocal rather than a global.