mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
std.debug: lock stderr mutex when panicking
The doc comments for this global said: "Locked to avoid interleaving panic messages from multiple threads." Huh? There's already a mutex for that, it's the stderr mutex. Lock that one instead.
This commit is contained in:
parent
0cef727e59
commit
55a9ea250c
@ -447,9 +447,6 @@ pub fn panicExtra(
|
||||
/// The counter is incremented/decremented atomically.
|
||||
var panicking = std.atomic.Value(u8).init(0);
|
||||
|
||||
// Locked to avoid interleaving panic messages from multiple threads.
|
||||
var panic_mutex = std.Thread.Mutex{};
|
||||
|
||||
/// Counts how many times the panic handler is invoked by this thread.
|
||||
/// This is used to catch and handle panics triggered by the panic handler.
|
||||
threadlocal var panic_stage: usize = 0;
|
||||
@ -474,8 +471,8 @@ pub fn panicImpl(trace: ?*const std.builtin.StackTrace, first_trace_addr: ?usize
|
||||
|
||||
// Make sure to release the mutex when done
|
||||
{
|
||||
panic_mutex.lock();
|
||||
defer panic_mutex.unlock();
|
||||
lockStdErr();
|
||||
defer unlockStdErr();
|
||||
|
||||
const stderr = io.getStdErr().writer();
|
||||
if (builtin.single_threaded) {
|
||||
@ -2604,8 +2601,8 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
|
||||
_ = panicking.fetchAdd(1, .seq_cst);
|
||||
|
||||
{
|
||||
panic_mutex.lock();
|
||||
defer panic_mutex.unlock();
|
||||
lockStdErr();
|
||||
defer unlockStdErr();
|
||||
|
||||
dumpSegfaultInfoPosix(sig, code, addr, ctx_ptr);
|
||||
}
|
||||
@ -2680,8 +2677,8 @@ fn handleSegfaultWindowsExtra(
|
||||
_ = panicking.fetchAdd(1, .seq_cst);
|
||||
|
||||
{
|
||||
panic_mutex.lock();
|
||||
defer panic_mutex.unlock();
|
||||
lockStdErr();
|
||||
defer unlockStdErr();
|
||||
|
||||
dumpSegfaultInfoWindows(info, msg, label);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user