Skip to content

Commit 26c249f

Browse files
committed
Document the global fallback
1 parent 118a744 commit 26c249f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

rayon-core/src/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,23 @@
2626
//! [`join()`]: struct.ThreadPool.html#method.join
2727
//! [`ThreadPoolBuilder`]: struct.ThreadPoolBuilder.html
2828
//!
29-
//! ## Restricting multiple versions
29+
//! # Global fallback when threading is unsupported
30+
//!
31+
//! Rayon uses `std` APIs for threading, but some targets have incomplete implementations that
32+
//! always return `Unsupported` errors. The WebAssembly `wasm32-unknown-unknown` and `wasm32-wasi`
33+
//! targets are notable examples of this. Rather than panicking on the unsupported error when
34+
//! creating the implicit global threadpool, Rayon configures a fallback mode instead.
35+
//!
36+
//! This fallback mode mostly functions as if it were using a single-threaded "pool", like setting
37+
//! `RAYON_NUM_THREADS=1`. For example, `join` will execute its two closures sequentially, since
38+
//! there is no other thread to share the work. However, since the pool is not running independent
39+
//! of the main thread, non-blocking calls like `spawn` may not execute at all, unless a lower-
40+
//! priority call like `broadcast` gives them an opening. The fallback mode does not try to emulate
41+
//! anything like thread preemption or `async` task switching.
42+
//!
43+
//! Explicit `ThreadPoolBuilder` methods always report their error without any fallback.
44+
//!
45+
//! # Restricting multiple versions
3046
//!
3147
//! In order to ensure proper coordination between threadpools, and especially
3248
//! to make sure there's only one global threadpool, `rayon-core` is actively

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@
7676
//! [the `collections` from `std`]: https://doc.rust-lang.org/std/collections/index.html
7777
//! [`std`]: https://doc.rust-lang.org/std/
7878
//!
79+
//! # Targets without threading
80+
//!
81+
//! Rayon has limited support for targets without `std` threading implementations.
82+
//! See the [`rayon_core`] documentation for more information about its global fallback.
83+
//!
7984
//! # Other questions?
8085
//!
8186
//! See [the Rayon FAQ][faq].

0 commit comments

Comments
 (0)