From 13263a2aa8bcf4e4aa84ac03c06732813f4e2ec0 Mon Sep 17 00:00:00 2001 From: Tatsuya Kawano Date: Fri, 10 Sep 2021 21:14:19 +0800 Subject: [PATCH] Support Linux on MIPS and ARMv5TE Ensure to set num threads to 1 for thread pools when `num_cpus::get()` returns 0. --- src/common/thread_pool.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/common/thread_pool.rs b/src/common/thread_pool.rs index 21ee5045..3550eafb 100644 --- a/src/common/thread_pool.rs +++ b/src/common/thread_pool.rs @@ -53,7 +53,10 @@ impl ThreadPoolRegistry { // and insert a new pool. let mut pools = REGISTRY.pools.write(); pools.entry(name).or_insert_with(|| { - let num_threads = num_cpus::get(); + // Some platforms may return 0. In that case, use 1. + // https://github.com/moka-rs/moka/pull/39#issuecomment-916888859 + // https://github.com/rust-lang/futures-rs/pull/1835 + let num_threads = num_cpus::get().max(1); let pool = ScheduledThreadPool::with_name(name.thread_name_template(), num_threads); let t_pool = ThreadPool {