Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adef8b4c3963c280c68965d21c29036a6c32da19
[simgrid.git] / examples / s4u / actor-join / s4u-actor-join.cpp
1 /* Copyright (c) 2017-2018. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "simgrid/s4u.hpp"
7
8 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
9
10 static void sleeper()
11 {
12   XBT_INFO("Sleeper started");
13   simgrid::s4u::this_actor::sleep_for(3);
14   XBT_INFO("I'm done. See you!");
15 }
16
17 static void master()
18 {
19   simgrid::s4u::ActorPtr actor;
20
21   XBT_INFO("Start sleeper");
22   actor = simgrid::s4u::Actor::create("sleeper from master", simgrid::s4u::Host::current(), sleeper);
23   XBT_INFO("Join the sleeper (timeout 2)");
24   actor->join(2);
25
26   XBT_INFO("Start sleeper");
27   actor = simgrid::s4u::Actor::create("sleeper from master", simgrid::s4u::Host::current(), sleeper);
28   XBT_INFO("Join the sleeper (timeout 4)");
29   actor->join(4);
30
31   XBT_INFO("Start sleeper");
32   actor = simgrid::s4u::Actor::create("sleeper from master", simgrid::s4u::Host::current(), sleeper);
33   XBT_INFO("Join the sleeper (timeout 2)");
34   actor->join(2);
35
36   XBT_INFO("Start sleeper");
37   actor = simgrid::s4u::Actor::create("sleeper from master", simgrid::s4u::Host::current(), sleeper);
38   XBT_INFO("Waiting 4");
39   simgrid::s4u::this_actor::sleep_for(4);
40   XBT_INFO("Join the sleeper after its end (timeout 1)");
41   actor->join(1);
42
43   XBT_INFO("Goodbye now!");
44
45   simgrid::s4u::this_actor::sleep_for(1);
46
47   XBT_INFO("Goodbye now!");
48 }
49
50 int main(int argc, char* argv[])
51 {
52   simgrid::s4u::Engine e(&argc, argv);
53   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
54
55   e.load_platform(argv[1]);
56
57   simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master);
58
59   e.run();
60
61   XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock());
62
63   return 0;
64 }