1 /* Copyright (c) 2010-2019. 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/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static int slave(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
13 XBT_INFO("Slave started");
15 XBT_INFO("I'm done. See you!");
19 static int master(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
21 msg_process_t process;
23 XBT_INFO("Start slave");
24 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
25 XBT_INFO("Join the slave (timeout 2)");
26 MSG_process_join(process, 2);
28 XBT_INFO("Start slave");
29 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
30 XBT_INFO("Join the slave (timeout 4)");
31 MSG_process_join(process, 4);
33 XBT_INFO("Start slave");
34 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
35 XBT_INFO("Join the slave (timeout 2)");
36 MSG_process_join(process, 2);
38 XBT_INFO("Start slave");
39 process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
40 MSG_process_ref(process); // We have to take that ref because the process will stop before we join it
41 XBT_INFO("Waiting 4");
43 XBT_INFO("Join the slave after its end (timeout 1)");
44 MSG_process_join(process, 1);
45 MSG_process_unref(process); // Avoid to leak memory
47 XBT_INFO("Goodbye now!");
51 XBT_INFO("Goodbye now!");
55 int main(int argc, char* argv[])
59 MSG_init(&argc, argv);
60 xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
62 MSG_create_environment(argv[1]);
64 MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
68 XBT_INFO("Simulation time %g", MSG_get_clock());