From 866ee4f1c52ae3e5a8ac95c9c5e61b019aa5eadb 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 287bed5d09..bccaf24ecd 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 d68cd1494b..195a457d3b 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,