Allows the caller to freely write to stderr until unlockStderr is called.
During the lock, any std.Progress information is cleared from the terminal.
The lock is recursive, so it is valid for the same thread to call
lockStderr multiple 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 Writer does not need to be manually flushed: flushing is
performed automatically when the matching unlockStderr call occurs.
This is a low-level debugging primitive that bypasses the Io interface,
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.lockStderr to integrate with the
application's chosen Io implementation.
pub fn lockStderr(buffer: []u8) Io.LockedStderr
pub 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.
};
}