From a2b556f1b0a48308c337dd0b4e57c4290d01001a Mon Sep 17 00:00:00 2001 From: Marcin Mielniczuk Date: Sun, 15 Dec 2019 19:27:12 +0100 Subject: [PATCH] Do not loop with nfds=0, timeout=-1 --- .../src/sys/windows/hostcalls_impl/misc.rs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs index b82054cdc6..c8c8f34ed6 100644 --- a/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs +++ b/crates/wasi-common/src/sys/windows/hostcalls_impl/misc.rs @@ -125,18 +125,13 @@ pub(crate) fn poll_oneoff( // With no events to listen, poll_oneoff just becomes a sleep. if fd_events.is_empty() { match timeout_duration { - Some(t) => { - thread::sleep(t); - return Ok(()); - } - None => { - // `poll` invoked with nfds = 0, timeout = -1 appears to be an infinite sleep - // The thread is not guanteed to remain parked forever, so we need to loop - loop { - thread::park(); - } - } + Some(t) => thread::sleep(t), + // `poll` invoked with nfds = 0, timeout = -1 appears to be an infinite sleep + // Even though the thread is not guanteed to remain parked forever, `poll(2)` + // mentions that spurious readiness notifications may occur, so it's probably fine + None => thread::park(), } + return Ok(()); } // Currently WASI file support is only (a) regular files (b) directories (c) symlinks on Windows,