diff --git a/library/std/src/sys/thread/unix.rs b/library/std/src/sys/thread/unix.rs index 22f9bfef5a383..dd6bd18f7a0e7 100644 --- a/library/std/src/sys/thread/unix.rs +++ b/library/std/src/sys/thread/unix.rs @@ -155,6 +155,7 @@ pub fn available_parallelism() -> io::Result> { target_os = "aix", target_vendor = "apple", target_os = "cygwin", + all(target_os = "wasi", target_feature = "atomics"), ) => { #[allow(unused_assignments)] #[allow(unused_mut)] @@ -314,6 +315,10 @@ pub fn available_parallelism() -> io::Result> { Ok(NonZero::new_unchecked(set.count_ones() as usize)) } } + all(target_os = "wasi", not(target_feature = "atomics")) => { + // Single-threaded WASM always has exactly one thread of execution. + Ok(NonZero::new(1).unwrap()) + } _ => { // FIXME: implement on Redox, l4re Err(io::const_error!(io::ErrorKind::Unsupported, "getting the number of hardware threads is not supported on the target platform")) diff --git a/library/std/tests/thread.rs b/library/std/tests/thread.rs index dc8eadd75148b..ef13ce44d3180 100644 --- a/library/std/tests/thread.rs +++ b/library/std/tests/thread.rs @@ -85,7 +85,6 @@ fn thread_local_hygeiene() { target_env = "sgx", target_os = "solid_asp3", target_os = "teeos", - target_os = "wasi" ), should_panic )]