Skip to content

Commit e431b4b

Browse files
committed
Document the global spawn_fifo
1 parent e047db6 commit e431b4b

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

rayon-core/src/spawn/mod.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ use unwind;
2424
/// by a mutex, or some such thing). If you want to compute a result,
2525
/// consider `spawn_future()`.
2626
///
27+
/// There is no guaranteed order of execution for spawns, given that
28+
/// other threads may steal tasks at any time. However, they are
29+
/// generally prioritized in a LIFO order on the thread from which
30+
/// they were spawned. Other threads always steal from the other end of
31+
/// the deque, like FIFO order. The idea is that "recent" tasks are
32+
/// most likely to be fresh in the local CPU's cache, while other
33+
/// threads can steal older "stale" tasks. For an alternate approach,
34+
/// consider [`spawn_fifo()`] instead.
35+
///
36+
/// [`spawn_fifo()`]: fn.spawn_fifo.html
37+
///
2738
/// # Panic handling
2839
///
2940
/// If this closure should panic, the resulting panic will be
@@ -98,7 +109,32 @@ where
98109
.as_job_ref()
99110
}
100111

101-
/// TODO: like `spawn`, but FIFO
112+
/// Fires off a task into the Rayon threadpool in the "static" or
113+
/// "global" scope. Just like a standard thread, this task is not
114+
/// tied to the current stack frame, and hence it cannot hold any
115+
/// references other than those with `'static` lifetime. If you want
116+
/// to spawn a task that references stack data, use [the `scope_fifo()`
117+
/// function](fn.scope_fifo.html) to create a scope.
118+
///
119+
/// The behavior is essentially the same as [the `spawn`
120+
/// function](fn.spawn.html), except that calls from the same thread
121+
/// will be prioritized in FIFO order. This is similar to the now-
122+
/// deprecated [`breadth_first`] option, except the effect is isolated
123+
/// to relative `spawn_fifo` calls, not all threadpool tasks.
124+
///
125+
/// For more details on this design, see Rayon [RFC #1].
126+
///
127+
/// [`breadth_first`]: struct.ThreadPoolBuilder.html#method.breadth_first
128+
/// [RFC #1]: https://github.com/rayon-rs/rfcs/blob/master/accepted/rfc0001-scope-scheduling.md
129+
///
130+
/// # Panic handling
131+
///
132+
/// If this closure should panic, the resulting panic will be
133+
/// propagated to the panic handler registered in the `ThreadPoolBuilder`,
134+
/// if any. See [`ThreadPoolBuilder::panic_handler()`][ph] for more
135+
/// details.
136+
///
137+
/// [ph]: struct.ThreadPoolBuilder.html#method.panic_handler
102138
pub fn spawn_fifo<F>(func: F)
103139
where
104140
F: FnOnce() + Send + 'static,

0 commit comments

Comments
 (0)