Logo AND Algorithmique Numérique Distribuée

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