1 /* Copyright (c) 2017-2023. The SimGrid Team. All rights reserved. */
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. */
6 #include "simgrid/s4u.hpp"
7 namespace sg4 = simgrid::s4u;
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_daemon, "Messages specific for this s4u example");
11 /* The worker actor, working for a while before leaving */
14 XBT_INFO("Let's do some work (for 10 sec on Boivin).");
15 sg4::this_actor::execute(980.95e6);
17 XBT_INFO("I'm done now. I leave even if it makes the daemon die.");
20 /* The daemon, displaying a message every 3 seconds until all other actors stop */
21 static void my_daemon()
23 sg4::Actor::self()->daemonize();
25 while (sg4::this_actor::get_host()->is_on()) {
26 XBT_INFO("Hello from the infinite loop");
27 sg4::this_actor::sleep_for(3.0);
30 XBT_INFO("I will never reach that point: daemons are killed when regular actors are done");
33 int main(int argc, char* argv[])
35 sg4::Engine e(&argc, argv);
37 e.load_platform(argv[1]);
38 sg4::Actor::create("worker", e.host_by_name("Boivin"), worker);
39 sg4::Actor::create("daemon", e.host_by_name("Tremblay"), my_daemon);