1 /* Copyright (c) 2007, 2009, 2010. The SimGrid Team.
2 * All rights reserved. */
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. */
7 #include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
8 #include "xbt/sysdep.h" /* calloc */
10 /* Create a log channel to have nice outputs. */
12 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
13 "Messages specific for this msg example");
15 /** Lazy guy function. This process suspends itself asap. */
16 static int slave(int argc, char *argv[])
19 XBT_INFO("Suspending myself");
20 MSG_process_suspend(MSG_process_self());
21 XBT_INFO("OK, OK. Let's work");
22 MSG_task_execute(MSG_task_create("toto", 1e9, 0, NULL));
25 } /* end_of_lazy_guy */
27 static int master(int argc, char *argv[])
29 m_process_t bob = NULL;
32 bob = MSG_process_create("slave", slave, NULL, MSG_get_host_by_name("bob"));
33 MSG_process_sleep(10.0);
35 XBT_INFO("Resume process");
36 MSG_process_resume(bob);
38 XBT_INFO("Kill process");
39 MSG_process_kill(bob);
41 XBT_INFO("OK, goodbye now.");
43 } /* end_of_dram_master */
46 static MSG_error_t test_all(const char *platform_file,
47 const char *application_file)
49 MSG_error_t res = MSG_OK;
51 MSG_create_environment(platform_file);
52 MSG_function_register("master", master);
53 MSG_function_register("slave", slave);
54 MSG_launch_application(application_file);
58 XBT_INFO("Simulation time %g", MSG_get_clock());
60 } /* end_of_test_all */
64 int main(int argc, char *argv[])
66 MSG_error_t res = MSG_OK;
68 MSG_init(&argc, argv);
70 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
71 XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
75 test_all(argv[1], argv[2]);