X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e08142f6b96c100165667fe1b647a28b6357b5ed..bdfa117ce4f85c77d50219cb2e115d88d3f35f8e:/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 906c5361c5..00f9307889 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-2021. 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 (1) { + 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); @@ -96,12 +94,12 @@ int main(int argc, char* argv[]) 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; }