From 9f1aae64f85b69a4b495498b5c802942a4c39143 Mon Sep 17 00:00:00 2001 From: Bharath M R Date: Sat, 24 Sep 2016 17:29:14 -0700 Subject: [PATCH] [Fixes #46] Use 1 less worker thread than number of threads The main thread does directory traversal. Hence number of threads = main Thread + number of worker threads. We should have atleast one worker thread. --- src/main.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e4f4b4f3..314c88dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,6 +28,7 @@ use std::process; use std::result; use std::sync::{Arc, Mutex}; use std::thread; +use std::cmp; use deque::{Stealer, Stolen}; use grep::Grep; @@ -102,7 +103,7 @@ fn run(args: Args) -> Result { let workq = { let (workq, stealer) = deque::new(); - for _ in 0..args.threads() { + for _ in 0..cmp::max(1, args.threads() - 1) { let worker = MultiWorker { chan_work: stealer.clone(), out: out.clone(),