1 /* Copyright (c) 2010-2021. 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"
12 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_join, "Messages specific for this example");
16 static void sleeper(int argc, char* argv[])
18 XBT_INFO("Sleeper started");
19 sg_actor_sleep_for(3);
20 XBT_INFO("I'm done. See you!");
23 static void master(int argc, char* argv[])
25 const_sg_actor_t actor;
27 XBT_INFO("Start sleeper");
28 actor = sg_actor_create("sleeper from master", sg_host_self(), sleeper, 0, NULL);
29 XBT_INFO("Join the sleeper (timeout 2)");
30 sg_actor_join(actor, 2);
32 XBT_INFO("Start sleeper");
33 actor = sg_actor_create("sleeper from master", sg_host_self(), sleeper, 0, NULL);
34 XBT_INFO("Join the sleeper (timeout 4)");
35 sg_actor_join(actor, 4);
37 XBT_INFO("Start sleeper");
38 actor = sg_actor_create("sleeper from master", sg_host_self(), sleeper, 0, NULL);
39 XBT_INFO("Join the sleeper (timeout 2)");
40 sg_actor_join(actor, 2);
42 XBT_INFO("Start sleeper");
43 actor = sg_actor_create("sleeper from master", sg_host_self(), sleeper, 0, NULL);
44 sg_actor_ref(actor); // We have to take that ref because the actor will stop before we join it
45 XBT_INFO("Waiting 4");
46 sg_actor_sleep_for(4);
47 XBT_INFO("Join the sleeper after its end (timeout 1)");
48 sg_actor_join(actor, 1);
49 sg_actor_unref(actor); // Avoid to leak memory
51 XBT_INFO("Goodbye now!");
53 sg_actor_sleep_for(1);
55 XBT_INFO("Goodbye now!");
58 int main(int argc, char* argv[])
60 simgrid_init(&argc, argv);
61 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
63 simgrid_load_platform(argv[1]);
65 sg_actor_create("master", sg_host_by_name("Tremblay"), master, 0, NULL);
69 XBT_INFO("Simulation time %g", simgrid_get_clock());