1 /* Bug report: https://github.com/mquinson/simgrid/issues/40
3 * Task.listen used to be on async mailboxes as it always returned false.
4 * This occures in Java and C, but is only tested here in C.
7 #include "simgrid/msg.h"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
11 static int server(int argc, char *argv[])
13 msg_task_t task = MSG_task_create("a", 0, 0, (char*)"Some data");
14 MSG_task_isend(task, "mailbox");
16 xbt_assert(MSG_task_listen("mailbox")); // True (1)
17 XBT_INFO("Task listen works on regular mailboxes");
19 MSG_task_receive(&task, "mailbox");
20 xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
21 MSG_task_destroy(task);
22 XBT_INFO("Data successfully received from regular mailbox");
24 MSG_mailbox_set_async("mailbox2");
25 task = MSG_task_create("b", 0, 0, (char*)"More data");
26 MSG_task_isend(task, "mailbox2");
28 xbt_assert(MSG_task_listen("mailbox2")); // used to break.
29 XBT_INFO("Task listen works on asynchronous mailboxes");
31 MSG_task_receive(&task, "mailbox2");
32 xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
33 MSG_task_destroy(task);
34 XBT_INFO("Data successfully received from asynchronous mailbox");
39 int main(int argc, char *argv[])
41 MSG_init(&argc, argv);
43 MSG_create_environment(argv[1]);
44 MSG_process_create("test", server, NULL, MSG_host_by_name("Tremblay"));