Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
test that joining a terminated process still works
[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("Start slave");
39   process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
40   XBT_INFO("Waiting 4");
41   MSG_process_sleep(4);
42   XBT_INFO("Join the slave (timeout 1)");
43   MSG_process_join(process, 1);
44
45   XBT_INFO("Goodbye now!");
46
47   MSG_process_sleep(1);
48
49   XBT_INFO("Goodbye now!");
50   return 0;
51 }
52
53 int main(int argc, char *argv[])
54 {
55   msg_error_t res;
56
57   MSG_init(&argc, argv);
58   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
59
60   MSG_create_environment(argv[1]);
61
62   MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
63
64   res = MSG_main();
65
66   XBT_INFO("Simulation time %g", MSG_get_clock());
67
68   return res != MSG_OK;
69 }