Logo AND Algorithmique Numérique Distribuée

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