Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix smpi_execute_benched.
[simgrid.git] / examples / s4u / actor-daemon / s4u_actor-daemon.cpp
1 /* Copyright (c) 2017. 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_actor_daemon, "Messages specific for this s4u example");
9
10 /* The worker process, working for a while before leaving */
11 static void worker()
12 {
13   XBT_INFO("Let's do some work (for 10 sec on Boivin).");
14   simgrid::s4u::this_actor::execute(980.95e6);
15
16   XBT_INFO("I'm done now. I leave even if it makes the daemon die.");
17 }
18
19 /* The daemon, displaying a message every 3 seconds until all other processes stop */
20 static void my_daemon()
21 {
22   simgrid::s4u::Actor::self()->daemonize();
23
24   while (1) {
25     XBT_INFO("Hello from the infinite loop");
26     simgrid::s4u::this_actor::sleep_for(3.0);
27   }
28
29   XBT_INFO("I will never reach that point: daemons are killed when regular processes are done");
30 }
31
32 int main(int argc, char* argv[])
33 {
34   simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
35
36   e->loadPlatform(argv[1]);
37   simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Boivin"), worker);
38   simgrid::s4u::Actor::createActor("daemon", simgrid::s4u::Host::by_name("Tremblay"), my_daemon);
39
40   e->run();
41
42   delete e;
43   return 0;
44 }