Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Delete unused -fprofile-arcs flags.
[simgrid.git] / teshsuite / msg / get_sender.c
1 /* Copyright (c) 2009, 2010. 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 <stdio.h>
8 #include "msg/msg.h"
9 #include <float.h>
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
12
13
14 static int send(int argc, char *argv[])
15 {
16   INFO0("Sending");
17   MSG_task_put(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_self(), 0);
18   MSG_process_sleep(1.);        /* FIXME: if the sender exits before the receiver calls get_sender(), bad thing happens */
19   INFO0("Exiting");
20   return 0;
21 }
22
23 static int receive(int argc, char *argv[])
24 {
25   INFO0("Receiving");
26   m_task_t task = NULL;
27   MSG_task_get_with_timeout(&task, 0, DBL_MAX);
28   xbt_assert0(MSG_task_get_sender(task), "No sender received");
29   INFO1("Got a message sent by '%s'",
30         MSG_process_get_name(MSG_task_get_sender(task)));
31   return 0;
32 }
33
34 /** Main function */
35 int main(int argc, char *argv[])
36 {
37   MSG_error_t res = MSG_OK;
38
39   MSG_global_init(&argc, argv);
40   MSG_set_channel_number(100);
41
42   /*   Application deployment */
43   MSG_function_register("send", &send);
44   MSG_function_register("receive", &receive);
45
46   MSG_create_environment(argv[1]);
47   MSG_launch_application(argv[1]);
48   res = MSG_main();
49   MSG_clean();
50   if (res == MSG_OK)
51     return 0;
52   else
53     return 1;
54 }