Skip to content

Commit 4cdd2df

Browse files
committed
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).
1 parent 10e23d1 commit 4cdd2df

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

tokio/src/runtime/park.rs

-5
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ impl ParkThread {
6565
pub(crate) fn park_timeout(&mut self, duration: Duration) {
6666
#[cfg(loom)]
6767
CURRENT_THREAD_PARK_COUNT.with(|count| count.fetch_add(1, SeqCst));
68-
69-
// Wasm doesn't have threads, so just sleep.
70-
#[cfg(not(target_family = "wasm"))]
7168
self.inner.park_timeout(duration);
72-
#[cfg(target_family = "wasm")]
73-
std::thread::sleep(duration);
7469
}
7570

7671
pub(crate) fn shutdown(&mut self) {

0 commit comments

Comments
 (0)