From 69f87e5418ea81e829a625fcc7de20c8d79d257e Mon Sep 17 00:00:00 2001 From: Rene Rivera Date: Tue, 29 Aug 2023 20:03:31 -0500 Subject: [PATCH] Fix min parallelism when threads fail to run. --- src/engine/tasks.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/engine/tasks.cpp b/src/engine/tasks.cpp index f9b4db61f5..72e32fc3e1 100644 --- a/src/engine/tasks.cpp +++ b/src/engine/tasks.cpp @@ -222,8 +222,15 @@ inline executor::implementation::implementation(unsigned parallelism) runners.reserve(parallelism); for (; parallelism > 0; --parallelism) { - running_count += 1; - runners.emplace_back([this]() { runner(); }); + try + { + runners.emplace_back([this]() { runner(); }); + running_count += 1; + } + catch (const std::system_error & e) + { + err_printf("Task execution error: %s"); + } } #endif } @@ -348,7 +355,8 @@ executor::~executor() { i->stop(); } std::shared_ptr executor::make(int parallelism) { - auto result = std::make_shared(*this, get_parallelism(parallelism)); + auto result = std::make_shared(*this, + std::min(unsigned(i->runners.size()), get_parallelism(parallelism))); i->push_group(result); return result; }