1 /* Copyright (c) 2009-2019. 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 "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
11 static int sender_fun(int argc, char *argv[])
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 */
20 static int receiver_fun(int argc, char *argv[])
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);
31 int main(int argc, char *argv[])
33 MSG_init(&argc, argv);
35 MSG_create_environment(argv[1]);
37 MSG_process_create("send", sender_fun, NULL, MSG_get_host_by_name("Tremblay"));
38 MSG_process_create("receive", receiver_fun, NULL, MSG_get_host_by_name("Tremblay"));
40 return MSG_main() != MSG_OK;