File tree 1 file changed +35
-0
lines changed
rayon-core/src/thread_pool 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,41 @@ impl ThreadPool {
80
80
/// thread-local data from the current thread will not be
81
81
/// accessible.
82
82
///
83
+ /// # Warning: execution order
84
+ ///
85
+ /// `install()` implicitly calls [`ThreadPool::yield_now()`],
86
+ /// potentially scheduling another task to run on the current thread. For
87
+ /// example:
88
+ ///
89
+ /// ```rust
90
+ /// # use rayon_core as rayon;
91
+ /// use rayon::iter::{IntoParallelIterator, ParallelIterator};
92
+ /// fn main() {
93
+ /// rayon::ThreadPoolBuilder::new().num_threads(1).build_global().unwrap();
94
+ /// let pool = rayon::ThreadPoolBuilder::default().build().unwrap();
95
+ /// (0..3).into_par_iter().for_each(|_| {
96
+ /// print!("one ");
97
+ /// pool.install(||{});
98
+ /// print!("two ");
99
+ /// });
100
+ /// }
101
+ /// ```
102
+ ///
103
+ /// Since we configured just one thread in the global pool, one might
104
+ /// expect this to run sequentially, producing:
105
+ ///
106
+ /// ```ascii
107
+ /// one two one two one two
108
+ /// ```
109
+ ///
110
+ /// However each call to `install()` yields implicitly, allowing rayon to
111
+ /// run several instances of the `for_each()` loop concurrently on the
112
+ /// single, global thread. The following output would be equally valid:
113
+ ///
114
+ /// ```ascii
115
+ /// one one two one two two
116
+ /// ```
117
+ ///
83
118
/// # Panics
84
119
///
85
120
/// If `op` should panic, that panic will be propagated.
You can’t perform that action at this time.
0 commit comments