From 4cdd2dfa8cd5ec0a68e77d02231ad295ab14758b Mon Sep 17 00:00:00 2001 From: Sebastian Urban Date: Mon, 16 Dec 2024 16:45:35 +0100 Subject: [PATCH] Fix thread parking on WebAssembly Sleeping instead of parking with a timeout is not okay, even on the WebAssembly target, which currently only supports the current thread runtime. Reasons: 1. A task may have registered a timer and also woken itself. Thus we need to continue execution immediately. 2. Even if Tokio only supports the current thread runtime on WebAssembly, there exist multi-threaded targets like wasm32-wasip1-threads. Thus a wake-up event can occur from another thread (outside the Tokio runtime). --- tokio/src/runtime/park.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tokio/src/runtime/park.rs b/tokio/src/runtime/park.rs index c260b7512be..72988be6c75 100644 --- a/tokio/src/runtime/park.rs +++ b/tokio/src/runtime/park.rs @@ -65,12 +65,7 @@ impl ParkThread { pub(crate) fn park_timeout(&mut self, duration: Duration) { #[cfg(loom)] CURRENT_THREAD_PARK_COUNT.with(|count| count.fetch_add(1, SeqCst)); - - // Wasm doesn't have threads, so just sleep. - #[cfg(not(target_family = "wasm"))] self.inner.park_timeout(duration); - #[cfg(target_family = "wasm")] - std::thread::sleep(duration); } pub(crate) fn shutdown(&mut self) {