From c89b0b4c8c15b05fb74a3d2b51ba7564f1b954ae Mon Sep 17 00:00:00 2001 From: Roman Date: Wed, 8 Aug 2018 18:33:01 +0300 Subject: [PATCH] Fix num CPUs in threadpool::builder::Builder::new (#530) Closes #400 --- tokio-threadpool/src/builder.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tokio-threadpool/src/builder.rs b/tokio-threadpool/src/builder.rs index 0e5a36e5e..11df6c49e 100644 --- a/tokio-threadpool/src/builder.rs +++ b/tokio-threadpool/src/builder.rs @@ -10,6 +10,7 @@ use std::error::Error; use std::fmt; use std::sync::Arc; use std::time::Duration; +use std::cmp::max; use num_cpus; use tokio_executor::Enter; @@ -92,7 +93,7 @@ impl Builder { /// # } /// ``` pub fn new() -> Builder { - let num_cpus = num_cpus::get(); + let num_cpus = max(1, num_cpus::get()); let new_park = Box::new(|_: &WorkerId| { Box::new(BoxedPark::new(DefaultPark::new())) @@ -136,7 +137,7 @@ impl Builder { /// ``` pub fn pool_size(&mut self, val: usize) -> &mut Self { assert!(val >= 1, "at least one thread required"); - assert!(val <= MAX_WORKERS, "max value is {}", 32768); + assert!(val <= MAX_WORKERS, "max value is {}", MAX_WORKERS); self.pool_size = val; self