Logo AND Algorithmique Numérique Distribuée

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