X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e709643ef0c5b61c6c878016c418bffa2b1b20cd..4baffc72bd0a35b39f68b498681754a1ea2ef381:/teshsuite/s4u/host-on-off/host-on-off.cpp diff --git a/teshsuite/s4u/host-on-off/host-on-off.cpp b/teshsuite/s4u/host-on-off/host-on-off.cpp index ff634b9da0..69e4b2593b 100644 --- a/teshsuite/s4u/host-on-off/host-on-off.cpp +++ b/teshsuite/s4u/host-on-off/host-on-off.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2020. The SimGrid Team. +/* Copyright (c) 2010-2022. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -10,25 +10,23 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example") static void worker() { - const std::string* payload; simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi"); while (true) { + std::unique_ptr payload; try { - payload = static_cast(mailbox->get()); + payload = mailbox->get_unique(); } catch (const simgrid::HostFailureException&) { XBT_DEBUG("The host has been turned off, this was expected"); return; } if (*payload == "finalize") { - delete payload; break; } simgrid::s4u::this_actor::execute(5E7); XBT_INFO("Task \"%s\" done", payload->c_str()); - delete payload; } XBT_INFO("I'm done. See you!"); } @@ -38,7 +36,7 @@ static void master() simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi"); simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter"); - std::string* payload = new std::string("task on"); + auto* payload = new std::string("task on"); XBT_INFO("Sending \"task on\""); mailbox->put_async(payload, 1E6)->wait_for(1); @@ -92,16 +90,16 @@ static void master() int main(int argc, char* argv[]) { simgrid::s4u::Engine e(&argc, argv); - xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]); + xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]); e.load_platform(argv[1]); - simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master); - simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker); + simgrid::s4u::Actor::create("master", e.host_by_name("Tremblay"), master); + simgrid::s4u::Actor::create("worker", e.host_by_name("Jupiter"), worker); e.run(); - XBT_INFO("Simulation time %g", e.get_clock()); + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); return 0; }