From 3d2477e5544262c314be3479c749462ba048d0a1 Mon Sep 17 00:00:00 2001 From: "andy.boot" Date: Sat, 18 Jan 2020 22:04:08 +0000 Subject: [PATCH] Allow dust to run on single core machines Force dust to use 2 threads if there is only 1 cpu JWalk breaks if it tries to run on a single cpu https://github.com/jessegrosjean/jwalk/issues/15 This is a hack because I can't figure out how to fix JWalk. This code and the num_cpu crate can be removed when the bug is fixed Also I have conflated cpus with cores while describing this issue. It is very difficult to test as I don't have a single core machine. --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9e63ede..a4bf17e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -96,12 +96,23 @@ fn main() { } }; - let threads = options.value_of("threads").and_then(|threads| { + let temp_threads = options.value_of("threads").and_then(|threads| { threads .parse::() .map_err(|_| eprintln!("Ignoring bad value for threads: {:?}", threads)) .ok() }); + // Bug in JWalk + // https://github.com/jessegrosjean/jwalk/issues/15 + // We force it to use 2 threads if there is only 1 cpu + // as JWalk breaks if it tries to run on a single cpu + let threads = { + if temp_threads.is_none() && num_cpus::get() == 1 { + Some(2) + } else { + temp_threads + } + }; let depth = options.value_of("depth").and_then(|depth| { depth