X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5ed37babb2fa9097abe82df299c0aa259ed84d5a..3203afd846219ef8b41cadda945ea0a98103c46f:/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp diff --git a/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp b/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp index 429fccd068..bab673122f 100644 --- a/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp +++ b/examples/cpp/synchro-mutex/s4u-synchro-mutex.cpp @@ -5,7 +5,7 @@ #include "simgrid/s4u.hpp" /* All of S4U */ #include "xbt/config.hpp" -#include /* std::mutex and std::lock_guard */ +#include /* std::mutex and std::scoped_lock */ namespace sg4 = simgrid::s4u; @@ -29,14 +29,14 @@ static void worker(sg4::MutexPtr mutex, int& result) mutex->unlock(); } -static void workerLockGuard(sg4::MutexPtr mutex, int& result) +static void workerScopedLock(sg4::MutexPtr mutex, int& result) { - // Simply use the std::lock_guard like this + // Simply use the std::scoped_lock like this // It's like a lock() that would do the unlock() automatically when getting out of scope - std::lock_guard lock(*mutex); + const std::scoped_lock lock(*mutex); // then you are in a safe zone - XBT_INFO("Hello s4u, I'm ready to compute after a lock_guard"); + XBT_INFO("Hello s4u, I'm ready to compute after a scoped_lock"); // update the results result += 1; XBT_INFO("I'm done, good bye"); @@ -54,7 +54,7 @@ int main(int argc, char** argv) for (int i = 0; i < cfg_actor_count; i++) { sg4::MutexPtr mutex = sg4::Mutex::create(); - sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), workerLockGuard, mutex, std::ref(result[i])); + sg4::Actor::create("worker", sg4::Host::by_name("Jupiter"), workerScopedLock, mutex, std::ref(result[i])); sg4::Actor::create("worker", sg4::Host::by_name("Tremblay"), worker, mutex, std::ref(result[i])); }