From 33dfa2d1347e9ed4dc05fbde909fe0c5ca9dac8f Mon Sep 17 00:00:00 2001 From: Shokunin <30949000+tetrisgm@users.noreply.github.com> Date: Thu, 22 Oct 2026 11:01:16 -0700 Subject: [PATCH] host_time: bound the Windows timer wait Even with per-thread timers, an INFINITE wait turns any missed signal into an indefinitely parked thread. Wait at most the requested sleep plus 2 ms. Co-Authored-By: Claude Opus 5.5 --- runtime/src/host_time.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/src/host_time.c b/runtime/src/host_time.c index cbd5664d..4fb5f435 100644 --- a/runtime/src/host_time.c +++ b/runtime/src/host_time.c @@ -86,8 +86,10 @@ void psx_host_sleep_micros(unsigned usec) if (hundred_ns >= 0) hundred_ns = -1LL; due.QuadPart = hundred_ns; - if (SetWaitableTimer(timer, &due, 0, NULL, NULL, FALSE) && - WaitForSingleObject(timer, INFINITE) == WAIT_OBJECT_0) { + /* Bounded: a missed signal costs at most the sleep plus 2 ms, never + * an indefinitely parked thread. */ + if (SetWaitableTimer(timer, &due, 0, NULL, NULL, FALSE)) { + (void)WaitForSingleObject(timer, (DWORD)(usec / 1000u) + 2u); return; } }