VERBOSE(ParallelExecutor) << "INITIAL JOBS : " << _ready_jobs.size() << std::endl;
- while (!_ready_jobs.empty() ||
- // TODO Enhance this not to iterate over the array
- std::any_of(_waiting_jobs.begin(), _waiting_jobs.end(),
- [](const std::unique_ptr<Job> &job) { return job != nullptr; }))
+ while (true)
{
std::unique_lock<std::mutex> lock{_mu_jobs};
+
+ // Check finish condition
+ if (_ready_jobs.empty() &&
+ // TODO Enhance this not to iterate over the array
+ !std::any_of(_waiting_jobs.begin(), _waiting_jobs.end(),
+ [](const std::unique_ptr<Job> &job) { return job != nullptr; }))
+ {
+ break;
+ }
+
if (_ready_jobs.empty())
{
_cv_jobs.wait(lock, [this] { return !_ready_jobs.empty(); });