Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Those two files are now compatible.
[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   XBT_INFO("Sending");
17   MSG_task_put(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_self(),
18                0);
19   MSG_process_sleep(1.);        /* FIXME: if the sender exits before the receiver calls get_sender(), bad thing happens */
20   XBT_INFO("Exiting");
21   return 0;
22 }
23
24 static int receive(int argc, char *argv[])
25 {
26   XBT_INFO("Receiving");
27   m_task_t task = NULL;
28   MSG_task_get_with_timeout(&task, 0, DBL_MAX);
29   xbt_assert(MSG_task_get_sender(task), "No sender received");
30   XBT_INFO("Got a message sent by '%s'",
31         MSG_process_get_name(MSG_task_get_sender(task)));
32   return 0;
33 }
34
35 /** Main function */
36 int main(int argc, char *argv[])
37 {
38   MSG_error_t res = MSG_OK;
39
40   MSG_global_init(&argc, argv);
41   MSG_set_channel_number(100);
42
43   /*   Application deployment */
44   MSG_function_register("send", &send);
45   MSG_function_register("receive", &receive);
46
47   MSG_create_environment(argv[1]);
48   MSG_launch_application(argv[1]);
49   res = MSG_main();
50   MSG_clean();
51   if (res == MSG_OK)
52     return 0;
53   else
54     return 1;
55 }