pub fn lockStderr(buffer: []u8) Io.LockedStderr buffer: []u8298
299
300
301
302
303
304
305pub fn lockStderr(buffer: []u8) Io.LockedStderr {
const io = std.Options.debug_io;
const prev = io.swapCancelProtection(.blocked);
defer _ = io.swapCancelProtection(prev);
return io.lockStderr(buffer, null) catch |err| switch (err) {
error.Canceled => unreachable, // Cancel protection enabled above.
};
}
Allows the caller to freely write to stderr until
unlockStderris called.During the lock, any
std.Progressinformation is cleared from the terminal.The lock is recursive, so it is valid for the same thread to call
lockStderrmultiple times, allowing the panic handler to safely dump the stack trace and panic message even if the mutex was held at the panic site.The returned
Writerdoes not need to be manually flushed: flushing is performed automatically when the matchingunlockStderrcall occurs.This is a low-level debugging primitive that bypasses the
Iointerface, writing directly to stderr using the most basic syscalls available. This function does not switch threads, switch stacks, or suspend.Alternatively, use the higher-level
Io.lockStderrto integrate with the application's chosenIoimplementation.