From 69f7cf60409e4abdfea42fac3cedde145f6bc8a6 Mon Sep 17 00:00:00 2001
From: Peter Bell <peterbell10@live.co.uk>
Date: Tue, 13 Aug 2019 15:44:20 +0100
Subject: [PATCH] FIX: Never assume hardware_concurrency > 0

---
 pocketfft_hdronly.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/pocketfft_hdronly.h b/pocketfft_hdronly.h
index a90bd40..ea282b6 100644
--- a/pocketfft_hdronly.h
+++ b/pocketfft_hdronly.h
@@ -721,6 +721,7 @@ namespace threading {
 
 constexpr size_t thread_id = 0;
 constexpr size_t num_threads = 1;
+constexpr size_t max_threads = 1;
 
 template <typename Func>
 void thread_map(size_t /* nthreads */, Func f)
@@ -730,6 +731,7 @@ void thread_map(size_t /* nthreads */, Func f)
 
 thread_local size_t thread_id = 0;
 thread_local size_t num_threads = 1;
+static const size_t max_threads = max(1u, thread::hardware_concurrency());
 
 class latch
   {
@@ -836,7 +838,7 @@ class thread_pool
       threads_(nthreads)
       { create_threads(); }
 
-    thread_pool(): thread_pool(thread::hardware_concurrency()) {}
+    thread_pool(): thread_pool(max_threads) {}
 
     ~thread_pool() { shutdown(); }
 
@@ -883,7 +885,7 @@ template <typename Func>
 void thread_map(size_t nthreads, Func f)
   {
   if (nthreads == 0)
-    nthreads = thread::hardware_concurrency();
+    nthreads = max_threads;
 
   if (nthreads == 1)
     { f(); return; }
-- 
GitLab