1 /* Copyright (c) 2017. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include <simgrid/s4u.hpp>
9 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_suspend, "Messages specific for this s4u example");
11 /* The Lazy guy only wants to sleep, but can be awaken by the dream_master process. */
12 static void lazy_guy()
14 XBT_INFO("Nobody's watching me ? Let's go to sleep.");
15 simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */
16 XBT_INFO("Uuuh ? Did somebody call me ?");
18 XBT_INFO("Going to sleep..."); /* - Then repetitively go to sleep, but got awaken */
19 simgrid::s4u::this_actor::sleep_for(10);
20 XBT_INFO("Mmm... waking up.");
22 XBT_INFO("Going to sleep one more time (for 10 sec)...");
23 simgrid::s4u::this_actor::sleep_for(10);
24 XBT_INFO("Waking up once for all!");
26 XBT_INFO("Ok, let's do some work, then (for 10 sec on Boivin).");
27 simgrid::s4u::this_actor::execute(980.95e6);
29 XBT_INFO("Mmmh, I'm done now. Goodbye.");
32 /* The Dream master: */
33 static void dream_master()
35 XBT_INFO("Let's create a lazy guy."); /* - Create a lazy_guy process */
36 simgrid::s4u::ActorPtr lazy = simgrid::s4u::Actor::createActor("Lazy", simgrid::s4u::this_actor::host(), lazy_guy);
37 XBT_INFO("Let's wait a little bit...");
38 simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
39 XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
40 lazy->resume(); /* - Then wake up the lazy_guy */
42 simgrid::s4u::this_actor::sleep_for(5); /* Repeat two times: */
43 XBT_INFO("Suspend the lazy guy while he's sleeping...");
44 lazy->suspend(); /* - Suspend the lazy_guy while he's asleep */
45 XBT_INFO("Let him finish his siesta.");
46 simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
47 XBT_INFO("Wake up, lazy guy!");
48 lazy->resume(); /* - Then wake up the lazy_guy again */
50 simgrid::s4u::this_actor::sleep_for(5);
51 XBT_INFO("Suspend again the lazy guy while he's sleeping...");
53 XBT_INFO("This time, don't let him finish his siesta.");
54 simgrid::s4u::this_actor::sleep_for(2);
55 XBT_INFO("Wake up, lazy guy!");
58 simgrid::s4u::this_actor::sleep_for(5);
59 XBT_INFO("Give a 2 seconds break to the lazy guy while he's working...");
61 simgrid::s4u::this_actor::sleep_for(2);
62 XBT_INFO("Back to work, lazy guy!");
65 XBT_INFO("OK, I'm done here.");
68 int main(int argc, char* argv[])
70 simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
71 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
73 e->loadPlatform(argv[1]); /* - Load the platform description */
74 std::vector<simgrid::s4u::Host*> list;
76 simgrid::s4u::Actor::createActor("dream_master", list.front(), dream_master);
78 e->run(); /* - Run the simulation */