1 /* Copyright (c) 2007, 2009-2014. 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 /** @addtogroup MSG_examples
17 * - <b>suspend/suspend.c</b>: Demonstrates how to suspend and resume processes using @ref MSG_process_suspend and @ref MSG_process_resume.
20 /** Lazy guy function. This process suspends itself asap. */
21 static int lazy_guy(int argc, char *argv[])
23 XBT_INFO("Nobody's watching me ? Let's go to sleep.");
24 MSG_process_suspend(MSG_process_self());
25 XBT_INFO("Uuuh ? Did somebody call me ?");
26 XBT_INFO("Mmmh, goodbye now.");
28 } /* end_of_lazy_guy */
30 /** Dream master function. This process creates a lazy_guy process and
31 resumes it 10 seconds later. */
32 static int dream_master(int argc, char *argv[])
34 msg_process_t lazy = NULL;
36 XBT_INFO("Let's create a lazy guy.");
37 lazy = MSG_process_create("Lazy", lazy_guy, NULL, MSG_host_self());
38 XBT_INFO("Let's wait a little bit...");
39 MSG_process_sleep(10.0);
40 XBT_INFO("Let's wake the lazy guy up! >:) BOOOOOUUUHHH!!!!");
41 MSG_process_resume(lazy);
42 XBT_INFO("OK, goodbye now.");
44 } /* end_of_dram_master */
47 static msg_error_t test_all(const char *platform_file,
48 const char *application_file)
50 msg_error_t res = MSG_OK;
52 { /* Simulation setting */
53 MSG_create_environment(platform_file);
55 { /* Application deployment */
56 MSG_function_register("dream_master", dream_master);
57 MSG_launch_application(application_file);
61 XBT_INFO("Simulation time %g", MSG_get_clock());
63 } /* end_of_test_all */
67 int main(int argc, char *argv[])
69 msg_error_t res = MSG_OK;
71 MSG_init(&argc, argv);
73 XBT_CRITICAL("Usage: %s platform_file deployment_file\n", argv[0]);
74 XBT_CRITICAL("example: %s msg_platform.xml msg_deployment_suspend.xml\n",
78 test_all(argv[1], argv[2]);