X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/b383052570bf2f171e76fbf038b0f85b63a987df..cb6448e71a64791c262d6c40c050cc0b8d8ed184:/examples/s4u/actions-comm/s4u_actions-comm.cpp diff --git a/examples/s4u/actions-comm/s4u_actions-comm.cpp b/examples/s4u/actions-comm/s4u_actions-comm.cpp index 360112702f..3e14881899 100644 --- a/examples/s4u/actions-comm/s4u_actions-comm.cpp +++ b/examples/s4u/actions-comm/s4u_actions-comm.cpp @@ -3,6 +3,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + #include "simgrid/msg.h" #include "simgrid/simix.h" /* semaphores for the barrier */ #include @@ -172,13 +174,16 @@ static void action_barrier(const char *const *action) processes_arrived_sofar = 0; } ACT_DEBUG("Entering barrier: %s (%d already there)", NAME, processes_arrived_sofar); - mutex->lock(); - if (++processes_arrived_sofar == communicator_size) { - cond->notify_all(); - mutex->unlock(); - } else { - cond->wait(mutex); - mutex->unlock(); + + { + std::unique_lock 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);