Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
365ebb34272ecb4129be5310f145e4327e0eecf0
[simgrid.git] / examples / msg / masterslave / masterslave_kill.c
1 /* Copyright (c) 2007, 2009-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 /** Lazy guy function. This process suspends itself asap.  */
12 static int slave(int argc, char *argv[])
13 {
14   XBT_INFO("Hello!");
15   XBT_INFO("Suspending myself");
16   MSG_process_suspend(MSG_process_self());
17   XBT_INFO("OK, OK. Let's work");
18   MSG_task_execute(MSG_task_create("toto", 1e9, 0, NULL));
19   XBT_INFO("Bye!");
20   return 0;
21 }
22
23 static int master(int argc, char *argv[])
24 {
25   msg_process_t bob = NULL;
26
27   XBT_INFO("Hello!");
28   bob = MSG_process_create("slave", slave, NULL, MSG_host_by_name("Fafard"));
29   MSG_process_sleep(10.0);
30
31   XBT_INFO("Resume process");
32   MSG_process_resume(bob);
33
34   XBT_INFO("Kill process");
35   MSG_process_kill(bob);
36
37   XBT_INFO("OK, goodbye now.");
38   return 0;
39 }
40
41 int main(int argc, char *argv[])
42 {
43   msg_error_t res = MSG_OK;
44
45   MSG_init(&argc, argv);
46   xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
47              "\tExample: %s msg_platform.xml msg_deployment_suspend.xml\n", argv[0], argv[0]);
48
49   MSG_create_environment(argv[1]);
50
51   MSG_function_register("master", master);
52   MSG_function_register("slave", slave);
53   MSG_launch_application(argv[2]);
54
55   res = MSG_main();
56
57   XBT_INFO("Simulation time %g", MSG_get_clock());
58
59   return res != MSG_OK;
60 }