Skip to content

Commit

Permalink
Fix min parallelism when threads fail to run.
Browse files Browse the repository at this point in the history
  • Loading branch information
grafikrobot committed Aug 30, 2023
1 parent 88e1880 commit 69f87e5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/engine/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -348,7 +355,8 @@ executor::~executor() { i->stop(); }

std::shared_ptr<group> executor::make(int parallelism)
{
auto result = std::make_shared<group>(*this, get_parallelism(parallelism));
auto result = std::make_shared<group>(*this,
std::min(unsigned(i->runners.size()), get_parallelism(parallelism)));
i->push_group(result);
return result;
}
Expand Down

0 comments on commit 69f87e5

Please sign in to comment.