From 9121ee5168e63a6a14af4b8e58a2c869db826e69 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 29 Jan 2026 15:03:33 -0800 Subject: [PATCH] std.Io.Threaded: handle TIMEOUT from NtDelayExceution --- lib/std/Io/Threaded.zig | 2 +- lib/std/os/windows/ntdll.zig | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/std/Io/Threaded.zig b/lib/std/Io/Threaded.zig index 287bed5d0994ff9aeed1b86b7eeb0bdef57dacd5..bccaf24ecd9c969b55b60a94a90d8a064b5cac7b 100644 --- a/lib/std/Io/Threaded.zig +++ b/lib/std/Io/Threaded.zig @@ -2761,7 +2761,7 @@ fn batchWaitWindows(t: *Threaded, b: *Io.Batch, timeout: Io.Timeout) Io.Batch.Wa const delay_rc = windows.ntdll.NtDelayExecution(windows.TRUE, &delay_interval); alertable_syscall.finish(); switch (delay_rc) { - .SUCCESS => { + .SUCCESS, .TIMEOUT => { // The thread woke due to the timeout. Although spurious // timeouts are OK, when no deadline is passed we must not // return `error.Timeout`. diff --git a/lib/std/os/windows/ntdll.zig b/lib/std/os/windows/ntdll.zig index d68cd1494b8392381187de4316a7155351687eae..195a457d3b86167051c1a6f9d9eb4415673eb021 100644 --- a/lib/std/os/windows/ntdll.zig +++ b/lib/std/os/windows/ntdll.zig @@ -594,6 +594,13 @@ pub extern "ntdll" fn NtCancelSynchronousIoFile( IoStatusBlock: *IO_STATUS_BLOCK, ) callconv(.winapi) NTSTATUS; +/// This function has been observed to return SUCCESS on timeout on Windows 10 +/// and TIMEOUT on Wine 10.0. +/// +/// This function has been observed on Windows 11 such that positive interval +/// is real time, which can cause waits to be interrupted by changing system +/// time, however negative intervals are not affected by changes to system +/// time. pub extern "ntdll" fn NtDelayExecution( Alertable: BOOLEAN, DelayInterval: *const LARGE_INTEGER, -- 2.54.0