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.
constuse_parking_sleep = switch (native_os) {
// On Windows, we can implement sleep either with `NtDelayExecution` (which is how `SleepEx` in
// kernel32 works) or `NtWaitForAlertByThreadId` (thread parking). We're already using the
// latter for futex, so we may as well use it for sleeping too, to maximise code reuse. I'm
// also more confident that it will always correctly handle the cancelation race (so "unpark"
// before "park" causes "park" to return immediately): it *seems* like alertable sleeps paired
// with `NtAlertThread` do actually do this too, but there could be some caveat (e.g. it might
// fail under some specific condition), whereas `NtWaitForAlertByThreadId` must reliably trigger
// this behavior because `RtlWaitOnAddress` relies on it.
.windows => true,
// These targets have `_lwp_park`, which is superior to POSIX nanosleep because it has a better
// cancelation mechanism.
.netbsd,
.illumos,
=> true,
else => false,
}