Commit 69f7cf60 authored by Peter Bell's avatar Peter Bell

FIX: Never assume hardware_concurrency > 0

parent c573384c
...@@ -721,6 +721,7 @@ namespace threading { ...@@ -721,6 +721,7 @@ namespace threading {
constexpr size_t thread_id = 0; constexpr size_t thread_id = 0;
constexpr size_t num_threads = 1; constexpr size_t num_threads = 1;
constexpr size_t max_threads = 1;
template <typename Func> template <typename Func>
void thread_map(size_t /* nthreads */, Func f) void thread_map(size_t /* nthreads */, Func f)
...@@ -730,6 +731,7 @@ 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 thread_id = 0;
thread_local size_t num_threads = 1; thread_local size_t num_threads = 1;
static const size_t max_threads = max(1u, thread::hardware_concurrency());
class latch class latch
{ {
...@@ -836,7 +838,7 @@ class thread_pool ...@@ -836,7 +838,7 @@ class thread_pool
threads_(nthreads) threads_(nthreads)
{ create_threads(); } { create_threads(); }
thread_pool(): thread_pool(thread::hardware_concurrency()) {} thread_pool(): thread_pool(max_threads) {}
~thread_pool() { shutdown(); } ~thread_pool() { shutdown(); }
...@@ -883,7 +885,7 @@ template <typename Func> ...@@ -883,7 +885,7 @@ template <typename Func>
void thread_map(size_t nthreads, Func f) void thread_map(size_t nthreads, Func f)
{ {
if (nthreads == 0) if (nthreads == 0)
nthreads = thread::hardware_concurrency(); nthreads = max_threads;
if (nthreads == 1) if (nthreads == 1)
{ f(); return; } { f(); return; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment