You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 30, 2025. It is now read-only.
At the time of writing, in the implementation of google::GetStackTrace() in src/stacktrace_libunwind-inl.h there is a global variable that enforces that only one thread may invoke libunwind at a time. However, libunwind is thread-safe. The comment above the variable declaration indicates that this is to protect against reentrancy issues:
// 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.staticbool g_now_entering = false;
Instead of using a global variable, it would be much better to use a thread-local variable to protect against these reentrancy issues. That should provide the needed reentrancy protection while allowing multiple threads to get stack traces at the same time. It would also allow for the removal of the atomic CAS operations on the g_now_entering variable.