Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8f6e9d8ca84a2d75b8538147848fa702691cfce8
[simgrid.git] / teshsuite / msg / process_join / process_join.c
1 /* Copyright (c) 2010-2014. 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 <stdio.h>
8 #include "msg/msg.h"            /* Yeah! If you want to use msg, you need to include msg/msg.h */
9 #include "xbt/sysdep.h"         /* calloc, printf */
10
11 /* Create a log channel to have nice outputs. */
12 #include "xbt/log.h"
13 #include "xbt/asserts.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
15                              "Messages specific for this msg example");
16
17 int master(int argc, char *argv[]);
18 int slave(int argc, char *argv[]);
19
20 /** Emitter function  */
21 int master(int argc, char *argv[])
22 {
23   msg_process_t process;
24
25   XBT_INFO("Start slave");
26   process =  MSG_process_create("slave from master",
27                                slave, NULL, MSG_host_self());
28   XBT_INFO("Join the slave (timeout 2)");
29   MSG_process_join(process, 2);
30
31   XBT_INFO("Start slave");
32   process =  MSG_process_create("slave from master",
33                                slave, NULL, MSG_host_self());
34   XBT_INFO("Join the slave (timeout 4)");
35   MSG_process_join(process, 4);
36
37   XBT_INFO("Start slave");
38   process =  MSG_process_create("slave from master",
39                                slave, NULL, MSG_host_self());
40   XBT_INFO("Join the slave (timeout 2)");
41   MSG_process_join(process, 2);
42
43   XBT_INFO("Goodbye now!");
44
45   MSG_process_sleep(1);
46
47   XBT_INFO("Goodbye now!");
48   return 0;
49 }                               /* end_of_master */
50
51 /** Receiver function  */
52 int slave(int argc, char *argv[])
53 {
54   XBT_INFO("Slave started");
55   MSG_process_sleep(3);
56   XBT_INFO("I'm done. See you!");
57   return 0;
58 }                               /* end_of_slave */
59
60 /** Main function */
61 int main(int argc, char *argv[])
62 {
63   msg_error_t res;
64   const char *platform_file;
65   const char *application_file;
66
67   MSG_init(&argc, argv);
68   if (argc != 3) {
69     printf("Usage: %s platform_file deployment_file\n", argv[0]);
70     printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
71     exit(1);
72   }
73   platform_file = argv[1];
74   application_file = argv[2];
75
76   /* MSG_config("workstation/model","KCCFLN05"); */
77   {                             /*  Simulation setting */
78     MSG_create_environment(platform_file);
79   }
80   {                             /*   Application deployment */
81     MSG_function_register("master", master);
82     MSG_function_register("slave", slave);
83
84     MSG_launch_application(application_file);
85   }
86   res = MSG_main();
87
88   XBT_INFO("Simulation time %g", MSG_get_clock());
89
90   if (res == MSG_OK)
91     return 0;
92   else
93     return 1;
94 }                               /* end_of_main */