| 1 |
use rayon::prelude::*; |
| 2 |
use rayon::ThreadPoolBuilder; |
| 3 |
|
| 4 |
#[test] |
| 5 |
#[cfg_attr(any(target_os = "emscripten", target_family = "wasm"), ignore)] |
| 6 |
fn cross_pool_busy() { |
| 7 |
let pool1 = ThreadPoolBuilder::new().num_threads(1).build().unwrap(); |
| 8 |
let pool2 = ThreadPoolBuilder::new().num_threads(1).build().unwrap(); |
| 9 |
|
| 10 |
let n: i32 = 100; |
| 11 |
let sum: i32 = pool1.install(move || { |
| 12 |
// Each item will block on pool2, but pool1 can continue processing other work from the |
| 13 |
// parallel iterator in the meantime. There's a chance that pool1 will still be awake to |
| 14 |
// see the latch set without being tickled, and then it will drop that stack job. The latch |
| 15 |
// internals must not assume that the job will still be alive after it's set! |
| 16 |
(1..=n) |
| 17 |
.into_par_iter() |
| 18 |
.map(|i| pool2.install(move || i)) |
| 19 |
.sum() |
| 20 |
}); |
| 21 |
assert_eq!(sum, n * (n + 1) / 2); |
| 22 |
} |