Skip to content

Commit

Permalink
Fix num CPUs in threadpool::builder::Builder::new (#530)
Browse files Browse the repository at this point in the history
Closes #400
  • Loading branch information
kpp authored and carllerche committed Aug 8, 2018
1 parent 6b1e4ab commit c89b0b4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tokio-threadpool/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c89b0b4

Please sign in to comment.