X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5dac84d65eed08644367fe040c41df162c02e5fa..417ed3b671abe3a71fa4106d23d0a432084cc207:/examples/cpp/io-dependent/s4u-io-dependent.cpp diff --git a/examples/cpp/io-dependent/s4u-io-dependent.cpp b/examples/cpp/io-dependent/s4u-io-dependent.cpp index 5b296f38b9..8788e10753 100644 --- a/examples/cpp/io-dependent/s4u-io-dependent.cpp +++ b/examples/cpp/io-dependent/s4u-io-dependent.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-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. */ @@ -8,15 +8,20 @@ #include XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example"); +namespace sg4 = simgrid::s4u; static void test() { - simgrid::s4u::ExecPtr bob_compute = simgrid::s4u::this_actor::exec_init(1e9); - simgrid::s4u::IoPtr bob_write = - simgrid::s4u::Host::current()->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::WRITE); - simgrid::s4u::IoPtr carl_read = - simgrid::s4u::Host::by_name("carl")->get_disks().front()->io_init(4000000, simgrid::s4u::Io::OpType::READ); - simgrid::s4u::ExecPtr carl_compute = simgrid::s4u::Host::by_name("carl")->exec_init(1e9); + std::vector pending_activities; + + sg4::ExecPtr bob_compute = sg4::this_actor::exec_init(1e9); + pending_activities.push_back(boost::dynamic_pointer_cast(bob_compute)); + sg4::IoPtr bob_write = sg4::Host::current()->get_disks().front()->io_init(4000000, sg4::Io::OpType::WRITE); + pending_activities.push_back(boost::dynamic_pointer_cast(bob_write)); + sg4::IoPtr carl_read = sg4::Host::by_name("carl")->get_disks().front()->io_init(4000000, sg4::Io::OpType::READ); + pending_activities.push_back(boost::dynamic_pointer_cast(carl_read)); + sg4::ExecPtr carl_compute = sg4::Host::by_name("carl")->exec_init(1e9); + pending_activities.push_back(boost::dynamic_pointer_cast(carl_compute)); // Name the activities (for logging purposes only) bob_compute->set_name("bob compute"); @@ -34,28 +39,29 @@ static void test() // Start the activities. bob_compute->start(); - bob_write->vetoable_start(); - carl_read->vetoable_start(); - carl_compute->vetoable_start(); - - // Wait for their completion (should be replaced by a wait_any_for at some point) - bob_compute->wait(); - bob_write->wait(); - carl_read->wait(); - carl_compute->wait(); + bob_write->start(); + carl_read->start(); + carl_compute->start(); + + // wait for the completion of all activities + while (not pending_activities.empty()) { + ssize_t changed_pos = sg4::Activity::wait_any(pending_activities); + XBT_INFO("Activity '%s' is complete", pending_activities[changed_pos]->get_cname()); + pending_activities.erase(pending_activities.begin() + changed_pos); + } } int main(int argc, char* argv[]) { - simgrid::s4u::Engine e(&argc, argv); + sg4::Engine e(&argc, argv); sg_storage_file_system_init(); e.load_platform(argv[1]); - simgrid::s4u::Actor::create("bob", simgrid::s4u::Host::by_name("bob"), test); + sg4::Actor::create("bob", e.host_by_name("bob"), test); e.run(); - XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); + XBT_INFO("Simulation time %g", sg4::Engine::get_clock()); return 0; }