Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c32ac97dd2b9dd948124be80cfbd10b25a5b85c1
[simgrid.git] / teshsuite / msg / host_on_off_wait / host_on_off_wait.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"            /* Yeah! If you want to use msg, you need to include simgrid/msg.h */
8
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
10
11 static int master(int argc, char *argv[])
12 {
13   msg_host_t jupiter = MSG_host_by_name("Jupiter");
14   XBT_INFO("Master waiting");
15   MSG_process_sleep(1);
16
17   XBT_INFO("Turning off the slave host");
18   MSG_host_off(jupiter);
19   XBT_INFO("Master has finished");
20
21   return 0;
22 }
23
24 static int slave(int argc, char *argv[])
25 {
26   XBT_INFO("Slave waiting");
27   // TODO, This should really be MSG_HOST_FAILURE
28   MSG_process_sleep(5);
29   XBT_ERROR("Slave should be off already.");
30   return 1;
31 }
32
33 int main(int argc, char *argv[])
34 {
35   msg_error_t res;
36
37   MSG_init(&argc, argv);
38   xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
39
40   MSG_create_environment(argv[1]);
41
42   MSG_process_create("master", master, NULL, MSG_get_host_by_name("Tremblay"));
43   MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("Jupiter"));
44
45   res = MSG_main();
46
47   XBT_INFO("Simulation time %g", MSG_get_clock());
48
49   return res != MSG_OK;
50 }