Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

lockStderr

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.

debug.lockStderr
pub fn lockStderr(buffer: []u8) Io.LockedStderr

File

lib/std/debug.zig:290

Code

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.
    };
}