Skip to content

Commit

Permalink
Add crash example
Browse files Browse the repository at this point in the history
  • Loading branch information
jessegrosjean committed Dec 13, 2022
1 parent 69c00ec commit c0b262b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/crash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
extern crate jwalk;

use jwalk::{WalkDir, Parallelism};
use rayon::prelude::*;

fn main() {
let rounds = vec![0, 1];

rayon::ThreadPoolBuilder::new()
.num_threads(1)
.build_global()
.expect("Failed to initialize worker thread pool");

let jwalk_pool = std::sync::Arc::new(
rayon::ThreadPoolBuilder::new()
.num_threads(1)
.build()
.unwrap(),
);

// Does finish if jwalk uses own pool with 1 thread
rounds.par_iter().for_each(|round| {
eprintln!("Round {round}…");
for _entry in WalkDir::new(".").parallelism(Parallelism::RayonExistingPool(jwalk_pool.clone())) {}
eprintln!("Round {round} completed");
});

// Does not finish if jwalk uses shared pool with 1 thread
rounds.par_iter().for_each(|round| {
eprintln!("Round {round}…");
for _entry in WalkDir::new(".") {}
eprintln!("Round {round} completed");
});
}

0 comments on commit c0b262b

Please sign in to comment.