X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/813e836067a1aa922c5fb1432300b7e6390ee352..HEAD:/teshsuite/mc/mutex-handling/mutex-handling.cpp diff --git a/teshsuite/mc/mutex-handling/mutex-handling.cpp b/teshsuite/mc/mutex-handling/mutex-handling.cpp index 56c0603897..8f986360a2 100644 --- a/teshsuite/mc/mutex-handling/mutex-handling.cpp +++ b/teshsuite/mc/mutex-handling/mutex-handling.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2015-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2015-2023. The SimGrid Team. All rights reserved. */ /* 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. */ @@ -24,20 +24,20 @@ #include "simgrid/s4u/Mailbox.hpp" #include "simgrid/s4u/Mutex.hpp" -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); +#include // std::unique_lock + +XBT_LOG_NEW_DEFAULT_CATEGORY(mutex_handling, "Messages specific for this test"); static int receiver(const char* box_name) { - auto mb = simgrid::s4u::Mailbox::by_name(box_name); - const int* payload; + auto* mb = simgrid::s4u::Mailbox::by_name(box_name); + std::unique_ptr payload; - payload = mb->get(); + payload = mb->get_unique(); MC_assert(*payload == 1); - delete payload; - payload = mb->get(); + payload = mb->get_unique(); MC_assert(*payload == 2); - delete payload; return 0; } @@ -45,24 +45,22 @@ static int receiver(const char* box_name) static int sender(const char* box_name, simgrid::s4u::MutexPtr mutex, int value) { auto* payload = new int(value); - auto mb = simgrid::s4u::Mailbox::by_name(box_name); - - if (mutex) - mutex->lock(); - - mb->put(static_cast(payload), 8); + auto* mb = simgrid::s4u::Mailbox::by_name(box_name); + std::unique_lock lock; if (mutex) - mutex->unlock(); + lock = std::unique_lock(*mutex); + mb->put(payload, 8); return 0; } int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); - xbt_assert(argc > 1, "Usage: %s platform_file\n" - "\tExample: %s msg_platform.xml\n", + xbt_assert(argc > 1, + "Usage: %s platform_file\n" + "\tExample: %s platform.xml\n", argv[0], argv[0]); simgrid::s4u::MutexPtr mutex; @@ -71,12 +69,12 @@ int main(int argc, char* argv[]) #endif e.load_platform(argv[1]); - simgrid::s4u::Actor::create("receiver", simgrid::s4u::Host::by_name("Jupiter"), receiver, "box"); - simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Boivin"), sender, "box", mutex, 1); - simgrid::s4u::Actor::create("sender", simgrid::s4u::Host::by_name("Fafard"), sender, "box", mutex, 2); + simgrid::s4u::Actor::create("receiver", e.host_by_name("Jupiter"), receiver, "box"); + simgrid::s4u::Actor::create("sender", e.host_by_name("Boivin"), sender, "box", mutex, 1); + simgrid::s4u::Actor::create("sender", e.host_by_name("Fafard"), sender, "box", mutex, 2); e.run(); - XBT_INFO("Simulation time %g", e.get_clock()); + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); return 0; }