Skip to content

Commit 4c96148

Browse files
taiki-ecramertj
authored andcommitted
Set ThreadPool::pool_size to 1 if num_cpus::get() returns 0
1 parent e9cd539 commit 4c96148

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

futures-executor/src/thread_pool.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ use futures_core::future::{Future, FutureObj};
44
use futures_core::task::{Context, Poll, Spawn, SpawnError};
55
use futures_util::future::FutureExt;
66
use futures_util::task::{ArcWake, waker_ref};
7+
use std::cmp;
8+
use std::fmt;
79
use std::io;
8-
use std::sync::{Arc, Mutex};
910
use std::sync::atomic::{AtomicUsize, Ordering};
1011
use std::sync::mpsc;
12+
use std::sync::{Arc, Mutex};
1113
use std::thread;
12-
use std::fmt;
1314

1415
/// A general-purpose thread pool for scheduling tasks that poll futures to
1516
/// completion.
@@ -203,7 +204,7 @@ impl ThreadPoolBuilder {
203204
/// See the other methods on this type for details on the defaults.
204205
pub fn new() -> ThreadPoolBuilder {
205206
ThreadPoolBuilder {
206-
pool_size: num_cpus::get(),
207+
pool_size: cmp::max(1, num_cpus::get()),
207208
stack_size: 0,
208209
name_prefix: None,
209210
after_start: None,

0 commit comments

Comments
 (0)