X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/417ed3b671abe3a71fa4106d23d0a432084cc207..305d783c9c259a5ec28836bdf697f73c6451aa2f:/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp diff --git a/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp b/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp index 0edd2ab68d..b660bf39fe 100644 --- a/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp +++ b/examples/cpp/synchro-condition-variable-waituntil/s4u-synchro-condition-variable-waituntil.cpp @@ -3,7 +3,7 @@ /* 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 /* std::mutex and std::lock_guard */ +#include /* std::mutex and std::scoped_lock */ #include /* All of S4U */ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "a sample log category"); @@ -12,13 +12,12 @@ namespace sg4 = simgrid::s4u; static void competitor(int id, sg4::ConditionVariablePtr cv, sg4::MutexPtr mtx, std::shared_ptr ready) { XBT_INFO("Entering the race..."); - std::unique_lock lck(*mtx); + std::unique_lock lock(*mtx); while (not *ready) { auto now = sg4::Engine::get_clock(); - if (cv->wait_until(lck, now + (id+1)*0.25) == std::cv_status::timeout) { + if (cv->wait_until(lock, now + (id + 1) * 0.25) == std::cv_status::timeout) { XBT_INFO("Out of wait_until (timeout)"); - } - else { + } else { XBT_INFO("Out of wait_until (YAY!)"); } } @@ -29,7 +28,7 @@ static void go(sg4::ConditionVariablePtr cv, sg4::MutexPtr mtx, std::shared_ptr< { XBT_INFO("Are you ready? ..."); sg4::this_actor::sleep_for(3); - std::unique_lock lck(*mtx); + const std::scoped_lock lock(*mtx); XBT_INFO("Go go go!"); *ready = true; cv->notify_all(); @@ -41,7 +40,7 @@ static void main_actor() auto cv = sg4::ConditionVariable::create(); auto ready = std::make_shared(false); - auto host = sg4::this_actor::get_host(); + auto* host = sg4::this_actor::get_host(); for (int i = 0; i < 10; ++i) sg4::Actor::create("competitor", host, competitor, i, cv, mtx, ready); sg4::Actor::create("go", host, go, cv, mtx, ready);