Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / teshsuite / msg / get_sender / get_sender.c
1 /* Copyright (c) 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 #include <float.h>
9 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
10
11 static int sender_fun(int argc, char *argv[])
12 {
13   XBT_INFO("Sending");
14   MSG_task_send(MSG_task_create("Blah", 0.0, 0.0, NULL), MSG_host_get_name(MSG_host_self()));
15   MSG_process_sleep(1.);     /* FIXME: if the sender exits before the receiver calls get_sender(), bad thing happens */
16   XBT_INFO("Exiting");
17   return 0;
18 }
19
20 static int receiver_fun(int argc, char *argv[])
21 {
22   XBT_INFO("Receiving");
23   msg_task_t task = NULL;
24   MSG_task_receive_with_timeout(&task, MSG_host_get_name(MSG_host_self()), DBL_MAX);
25   xbt_assert(MSG_task_get_sender(task), "No sender received");
26   XBT_INFO("Got a message sent by '%s'", MSG_process_get_name(MSG_task_get_sender(task)));
27   MSG_task_destroy(task);
28   return 0;
29 }
30
31 int main(int argc, char *argv[])
32 {
33   msg_error_t res = MSG_OK;
34
35   MSG_init(&argc, argv);
36
37   MSG_create_environment(argv[1]);
38
39   MSG_process_create("send", sender_fun, NULL, MSG_get_host_by_name("Tremblay"));
40   MSG_process_create("receive", receiver_fun, NULL, MSG_get_host_by_name("Tremblay"));
41
42   res = MSG_main();
43   return res != MSG_OK;
44 }