Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Restore the barrier as it was
[simgrid.git] / examples / s4u / actions-comm / s4u_actions-comm.cpp
index 35f4ecf3ccdedd07d9f1ad2217635dc42ad10e2f..826d6c97ca168023ef73581a6b28a64b7da8a0ee 100644 (file)
@@ -173,13 +173,15 @@ static void action_barrier(const char *const *action)
   }
   ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar);
 
-  std::unique_lock<simgrid::s4u::Mutex> lock(*mutex);
-  if (++processes_arrived_sofar == communicator_size) {
-    // We can notify without the lock:
-    lock.unlock();
-    cond->notify_all();
-  } else {
-    cond->wait(lock);
+  {
+    std::unique_lock<simgrid::s4u::Mutex> lock(*mutex);
+    if (++processes_arrived_sofar == communicator_size) {
+      // We can notify without the lock:
+      lock.unlock();
+      cond->notify_all();
+    } else {
+      cond->wait(lock);
+    }
   }
 
   ACT_DEBUG("Exiting barrier: %s", NAME);