1 /* Copyright (c) 2010-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"
12 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_join, "Messages specific for this example");
16 static void sleeper(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED 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(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
27 XBT_INFO("Start sleeper");
28 actor = sg_actor_init("sleeper from master", sg_host_self());
29 sg_actor_start(actor, sleeper, 0, NULL);
30 XBT_INFO("Join the sleeper (timeout 2)");
31 sg_actor_join(actor, 2);
33 XBT_INFO("Start sleeper");
34 actor = sg_actor_init("sleeper from master", sg_host_self());
35 sg_actor_start(actor, sleeper, 0, NULL);
36 XBT_INFO("Join the sleeper (timeout 4)");
37 sg_actor_join(actor, 4);
39 XBT_INFO("Start sleeper");
40 actor = sg_actor_init("sleeper from master", sg_host_self());
41 sg_actor_start(actor, sleeper, 0, NULL);
42 XBT_INFO("Join the sleeper (timeout 2)");
43 sg_actor_join(actor, 2);
45 XBT_INFO("Start sleeper");
46 actor = sg_actor_init("sleeper from master", sg_host_self());
47 sg_actor_start(actor, sleeper, 0, NULL);
48 sg_actor_ref(actor); // We have to take that ref because the actor will stop before we join it
49 XBT_INFO("Waiting 4");
50 sg_actor_sleep_for(4);
51 XBT_INFO("Join the sleeper after its end (timeout 1)");
52 sg_actor_join(actor, 1);
53 sg_actor_unref(actor); // Avoid to leak memory
55 XBT_INFO("Goodbye now!");
57 sg_actor_sleep_for(1);
59 XBT_INFO("Goodbye now!");
62 int main(int argc, char* argv[])
64 simgrid_init(&argc, argv);
65 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
67 simgrid_load_platform(argv[1]);
69 sg_actor_t actor = sg_actor_init("master", sg_host_by_name("Tremblay"));
70 sg_actor_start(actor, master, 0, NULL);
74 XBT_INFO("Simulation time %g", simgrid_get_clock());