1 /* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include "simgrid/s4u.hpp"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10 static void monitor(simgrid::s4u::ExecPtr activity)
12 while (not activity->test()) {
13 XBT_INFO("activity remaining duration: %g (%.0f%%)", activity->get_remaining(),
14 100 * activity->get_remaining_ratio());
15 simgrid::s4u::this_actor::sleep_for(5);
17 XBT_INFO("My task is over.");
20 static void executor()
22 XBT_INFO("Create one monitored task, and wait for it");
23 simgrid::s4u::ExecPtr activity = simgrid::s4u::this_actor::exec_async(1e9);
24 simgrid::s4u::Actor::create("monitor 1", simgrid::s4u::Host::by_name("Tremblay"), monitor, activity);
25 activity->wait(); // This blocks until the activity is over
26 XBT_INFO("The monitored task is over. Let's start 3 of them now.");
27 simgrid::s4u::Actor::create("monitor 2", simgrid::s4u::Host::by_name("Jupiter"), monitor,
28 simgrid::s4u::this_actor::exec_async(1e9));
29 simgrid::s4u::Actor::create("monitor 3", simgrid::s4u::Host::by_name("Ginette"), monitor,
30 simgrid::s4u::this_actor::exec_async(1e9));
31 simgrid::s4u::Actor::create("monitor 4", simgrid::s4u::Host::by_name("Bourassa"), monitor,
32 simgrid::s4u::this_actor::exec_async(1e9));
33 XBT_INFO("All activities are started; finish now");
34 // Waiting execution activities is not mandatory: they go to completion once started
36 // No memory is leaked here: activities are automatically refcounted, thanks to C++ smart pointers
39 int main(int argc, char* argv[])
41 simgrid::s4u::Engine e(&argc, argv);
42 e.load_platform(argv[1]);
44 simgrid::s4u::Actor::create("executor", simgrid::s4u::Host::by_name("Fafard"), executor);