1 /* Copyright (c) 2007-2020. 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 process. */
17 static void lazy_guy(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED 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(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
40 XBT_INFO("Let's create a lazy guy."); /* - Create a lazy_guy process */
41 sg_actor_t lazy = sg_actor_init("Lazy", sg_host_self());
42 sg_actor_start(lazy, lazy_guy, 0, NULL);
43 XBT_INFO("Let's wait a little bit...");
44 sg_actor_sleep_for(10.0); /* - Wait for 10 seconds */
45 XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
46 sg_actor_resume(lazy); /* - Then wake up the lazy_guy */
48 sg_actor_sleep_for(5.0); /* Repeat two times: */
49 XBT_INFO("Suspend the lazy guy while he's sleeping...");
50 sg_actor_suspend(lazy); /* - Suspend the lazy_guy while he's asleep */
51 XBT_INFO("Let him finish his siesta.");
52 sg_actor_sleep_for(10.0); /* - Wait for 10 seconds */
53 XBT_INFO("Wake up, lazy guy!");
54 sg_actor_resume(lazy); /* - Then wake up the lazy_guy again */
56 sg_actor_sleep_for(5.0);
57 XBT_INFO("Suspend again the lazy guy while he's sleeping...");
58 sg_actor_suspend(lazy);
59 XBT_INFO("This time, don't let him finish his siesta.");
60 sg_actor_sleep_for(2.0);
61 XBT_INFO("Wake up, lazy guy!");
62 sg_actor_resume(lazy);
64 sg_actor_sleep_for(5.0);
65 XBT_INFO("Give a 2 seconds break to the lazy guy while he's working...");
66 sg_actor_suspend(lazy);
67 sg_actor_sleep_for(2.0);
68 XBT_INFO("Back to work, lazy guy!");
69 sg_actor_resume(lazy);
71 XBT_INFO("OK, I'm done here.");
74 int main(int argc, char* argv[])
76 simgrid_init(&argc, argv);
77 xbt_assert(argc > 1, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
79 simgrid_load_platform(argv[1]);
80 simgrid_register_function("dream_master", dream_master);
82 sg_actor_t actor = sg_actor_init("dream_master", sg_host_by_name("Boivin"));
83 sg_actor_start(actor, dream_master, 0, NULL);