Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[s4u] Restore the barrier as it was
authorGabriel Corona <gabriel.corona@loria.fr>
Fri, 24 Jun 2016 14:31:59 +0000 (16:31 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Fri, 24 Jun 2016 14:32:35 +0000 (16:32 +0200)
examples/s4u/actions-comm/s4u_actions-comm.cpp

index 35f4ecf..826d6c9 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);