X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/6a583168b07434258d65e69fd1779b704a0e81fb..9f2dfd25486ba89c4adaa54d774092c0b9756361:/examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.cpp diff --git a/examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.cpp b/examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.cpp index 9e33fbbb0f..fcc6878548 100644 --- a/examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.cpp +++ b/examples/cpp/mc-bugged2-liveness/s4u-mc-bugged2-liveness.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2012-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2012-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. */ @@ -13,23 +13,24 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(bugged2_liveness, "my log messages"); +namespace sg4 = simgrid::s4u; class Message { public: - enum class Kind { GRANT, NOT_GRANT, REQUEST, RELEASE }; + enum class Kind { GRANT, NOT_GRANT, REQUEST }; Kind kind = Kind::GRANT; - simgrid::s4u::Mailbox* return_mailbox = nullptr; - explicit Message(Message::Kind kind, simgrid::s4u::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {} + sg4::Mailbox* return_mailbox = nullptr; + explicit Message(Message::Kind kind, sg4::Mailbox* mbox) : kind(kind), return_mailbox(mbox) {} }; int cs = 0; static void coordinator() { - int CS_used = 0; // initially the CS is idle - std::queue requests; + bool CS_used = false; // initially the CS is idle + std::queue requests; - simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator"); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("coordinator"); while (true) { auto m = mbox->get_unique(); @@ -40,24 +41,24 @@ static void coordinator() } else { // can serve it immediately XBT_INFO("CS idle. Grant immediately"); m->return_mailbox->put(new Message(Message::Kind::GRANT, mbox), 1000); - CS_used = 1; + CS_used = true; } } else { // that's a release. Check if someone was waiting for the lock XBT_INFO("CS release. resource now idle"); - CS_used = 0; + CS_used = false; } } } static void client(int id) { - aid_t my_pid = simgrid::s4u::this_actor::get_pid(); + aid_t my_pid = sg4::this_actor::get_pid(); - simgrid::s4u::Mailbox* my_mailbox = simgrid::s4u::Mailbox::by_name(std::to_string(id)); + sg4::Mailbox* my_mailbox = sg4::Mailbox::by_name(std::to_string(id)); while (true) { XBT_INFO("Client (%d) asks the request", id); - simgrid::s4u::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000); + sg4::Mailbox::by_name("coordinator")->put(new Message(Message::Kind::REQUEST, my_mailbox), 1000); auto grant = my_mailbox->get_unique(); @@ -69,21 +70,21 @@ static void client(int id) XBT_INFO("Client (%d) got the answer (not grant). Try again", id); } - simgrid::s4u::this_actor::sleep_for(my_pid); + sg4::this_actor::sleep_for(my_pid); } } int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); MC_automaton_new_propositional_symbol_pointer("cs", &cs); e.load_platform(argv[1]); - simgrid::s4u::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator); - simgrid::s4u::Actor::create("client", e.host_by_name("Fafard"), client, 1); - simgrid::s4u::Actor::create("client", e.host_by_name("Boivin"), client, 2); + sg4::Actor::create("coordinator", e.host_by_name("Tremblay"), coordinator); + sg4::Actor::create("client", e.host_by_name("Fafard"), client, 1); + sg4::Actor::create("client", e.host_by_name("Boivin"), client, 2); e.run();