Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
oops
[simgrid.git] / teshsuite / msg / process_join / process_join.c
1 /* Copyright (c) 2010-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "simgrid/msg.h"
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int slave(int argc, char *argv[])
12 {
13   XBT_INFO("Slave started");
14   MSG_process_sleep(3);
15   XBT_INFO("I'm done. See you!");
16   return 0;
17 }
18
19 static int master(int argc, char *argv[])
20 {
21   msg_process_t process;
22
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);
27
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);
32
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);
37
38   XBT_INFO("Goodbye now!");
39
40   MSG_process_sleep(1);
41
42   XBT_INFO("Goodbye now!");
43   return 0;
44 }
45
46 int main(int argc, char *argv[])
47 {
48   msg_error_t res;
49
50   MSG_init(&argc, argv);
51   xbt_assert(argc == 3, "Usage: %s platform_file deployment_file\n"
52              "\tExample: %s msg_platform.xml msg_deployment.xml\n", argv[0], argv[0]);
53
54   MSG_create_environment(argv[1]);
55
56   MSG_function_register("master", master);
57   MSG_function_register("slave", slave);
58   MSG_launch_application(argv[2]);
59
60   res = MSG_main();
61
62   XBT_INFO("Simulation time %g", MSG_get_clock());
63
64   return res != MSG_OK;
65 }