Skip to content

Commit 936093f

Browse files
andrewdavidmackenziecuviper
authored andcommitted
Use std::thread::available_parallelism() instead of num_cpus dependency
1 parent 2a342a6 commit 936093f

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

rayon-core/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ categories = ["concurrency"]
1717

1818
# Some dependencies may not be their latest version, in order to support older rustc.
1919
[dependencies]
20-
num_cpus = "1.2"
2120
crossbeam-channel = "0.5.0"
2221
crossbeam-deque = "0.8.1"
2322
crossbeam-utils = "0.8.0"

rayon-core/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ use std::fmt;
7373
use std::io;
7474
use std::marker::PhantomData;
7575
use std::str::FromStr;
76+
use std::thread;
7677

7778
#[macro_use]
7879
mod log;
@@ -463,7 +464,8 @@ impl<S> ThreadPoolBuilder<S> {
463464
.and_then(|s| usize::from_str(&s).ok())
464465
{
465466
Some(x) if x > 0 => return x,
466-
Some(x) if x == 0 => return num_cpus::get(),
467+
Some(x) if x == 0 => return thread::available_parallelism()
468+
.map(|n| n.get()).unwrap_or(1),
467469
_ => {}
468470
}
469471

@@ -473,7 +475,7 @@ impl<S> ThreadPoolBuilder<S> {
473475
.and_then(|s| usize::from_str(&s).ok())
474476
{
475477
Some(x) if x > 0 => x,
476-
_ => num_cpus::get(),
478+
_ => thread::available_parallelism().map(|n| n.get()).unwrap_or(1)
477479
}
478480
}
479481
}

0 commit comments

Comments
 (0)