Fix parallel executor finishing condition (#5429)
author이한종/On-Device Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Thu, 20 Jun 2019 03:56:21 +0000 (12:56 +0900)
committer오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Thu, 20 Jun 2019 03:56:21 +0000 (12:56 +0900)
Finishing condition must be processed with the lock, so the condition is
now inside the `while` body.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/core/src/exec/ParallelExecutor.cc

index 14a18d3..9a06086 100644 (file)
@@ -93,12 +93,19 @@ void ParallelExecutor::executeImpl()
 
   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(); });