Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sleep activities throw exception on host failure
[simgrid.git] / teshsuite / s4u / host_on_off_wait / host_on_off_wait.cpp
1 /* Copyright (c) 2010-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 #include <xbt/ex.hpp>
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
10
11 static void master()
12 {
13   simgrid::s4u::Host* jupiter = simgrid::s4u::Host::by_name("Jupiter");
14   XBT_INFO("Master waiting");
15   simgrid::s4u::this_actor::sleep_for(1);
16
17   XBT_INFO("Turning off the worker host");
18   jupiter->turn_off();
19   XBT_INFO("Master has finished");
20 }
21
22 static void worker()
23 {
24   XBT_INFO("Worker waiting");
25   try {
26     simgrid::s4u::this_actor::sleep_for(5);
27   } catch (xbt_ex& e) {
28     if (e.category == host_error) {
29       XBT_INFO("The host has died ... as expected.");
30     } else {
31       XBT_ERROR("An unexpected exception has been raised.");
32       throw;
33     }
34   }
35 }
36
37 int main(int argc, char* argv[])
38 {
39   simgrid::s4u::Engine e(&argc, argv);
40   e.load_platform(argv[1]);
41
42   simgrid::s4u::Actor::create("master", simgrid::s4u::Host::by_name("Tremblay"), master);
43   simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Jupiter"), worker);
44
45   e.run();
46   XBT_INFO("Simulation time %g", e.get_clock());
47
48   return 0;
49 }