1 /* Copyright (c) 2007-2023. 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/actor.h"
8 #include "simgrid/engine.h"
9 #include "simgrid/host.h"
11 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_suspend, "Messages specific for this example");
16 /* The Lazy guy only wants to sleep, but can be awaken by the dream_master actor. */
17 static void lazy_guy(int argc, char* argv[])
19 XBT_INFO("Nobody's watching me ? Let's go to sleep.");
20 sg_actor_suspend(sg_actor_self()); /* - Start by suspending itself */
21 XBT_INFO("Uuuh ? Did somebody call me ?");
23 XBT_INFO("Going to sleep..."); /* - Then repetitively go to sleep, but got awaken */
24 sg_actor_sleep_for(10.0);
25 XBT_INFO("Mmm... waking up.");
27 XBT_INFO("Going to sleep one more time (for 10 sec)...");
28 sg_actor_sleep_for(10.0);
29 XBT_INFO("Waking up once for all!");
31 XBT_INFO("Ok, let's do some work, then (for 10 sec on Boivin).");
32 sg_actor_execute(980.95e6);
34 XBT_INFO("Mmmh, I'm done now. Goodbye.");
37 /* The Dream master: */
38 static void dream_master(int argc, char* argv[])
40 XBT_INFO("Let's create a lazy guy."); /* - Create a lazy_guy actor */
41 sg_actor_t lazy = sg_actor_create("Lazy", sg_host_self(), lazy_guy, 0, NULL);
42 XBT_INFO("Let's wait a little bit...");
43 sg_actor_sleep_for(10.0); /* - Wait for 10 seconds */
44 XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
45 sg_actor_resume(lazy); /* - Then wake up the lazy_guy */
47 sg_actor_sleep_for(5.0); /* Repeat two times: */
48 XBT_INFO("Suspend the lazy guy while he's sleeping...");
49 sg_actor_suspend(lazy); /* - Suspend the lazy_guy while he's asleep */
50 XBT_INFO("Let him finish his siesta.");
51 sg_actor_sleep_for(10.0); /* - Wait for 10 seconds */
52 XBT_INFO("Wake up, lazy guy!");
53 sg_actor_resume(lazy); /* - Then wake up the lazy_guy again */
55 sg_actor_sleep_for(5.0);
56 XBT_INFO("Suspend again the lazy guy while he's sleeping...");
57 sg_actor_suspend(lazy);
58 XBT_INFO("This time, don't let him finish his siesta.");
59 sg_actor_sleep_for(2.0);
60 XBT_INFO("Wake up, lazy guy!");
61 sg_actor_resume(lazy);
63 sg_actor_sleep_for(5.0);
64 XBT_INFO("Give a 2 seconds break to the lazy guy while he's working...");
65 sg_actor_suspend(lazy);
66 sg_actor_sleep_for(2.0);
67 XBT_INFO("Back to work, lazy guy!");
68 sg_actor_resume(lazy);
70 XBT_INFO("OK, I'm done here.");
73 int main(int argc, char* argv[])
75 simgrid_init(&argc, argv);
76 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s platform.xml\n", argv[0], argv[0]);
78 simgrid_load_platform(argv[1]);
79 simgrid_register_function("dream_master", dream_master);
81 sg_actor_create("dream_master", sg_host_by_name("Boivin"), dream_master, 0, NULL);