teshsuite/msg/host_on_off/host_on_off_recv
teshsuite/msg/host_on_off/host_on_off_wait
teshsuite/msg/host_on_off_processes/host_on_off_processes
+teshsuite/msg/listen_async/listen_async
teshsuite/msg/pid/pid
teshsuite/msg/process_join/process_join
teshsuite/msg/process/process
-/* Copyright (c) 2004-2015. The SimGrid Team.
- * All rights reserved. */
+/* Copyright (c) 2004-2016. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "src/simix/smx_private.h" /* MSG_task_listen looks inside the rdv directly. Not clean. */
#include "msg_private.h"
#include "mc/mc.h"
#include "xbt/log.h"
*/
int MSG_task_listen(const char *alias)
{
- return !MSG_mailbox_is_empty(MSG_mailbox_get_by_alias(alias));
+ smx_rdv_t rdv = MSG_mailbox_get_by_alias(alias);
+ return !MSG_mailbox_is_empty(rdv) || (rdv->permanent_receiver && xbt_fifo_size(rdv->done_comm_fifo)!=0);
}
/** \ingroup msg_task_usage
--- /dev/null
+add_executable (listen_async listen_async.c)
+target_link_libraries(listen_async simgrid)
+
+set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/listen_async.tesh PARENT_SCOPE)
+set(teshsuite_src ${teshsuite_src} ${CMAKE_CURRENT_SOURCE_DIR}/listen_async.c PARENT_SCOPE)
+
+ADD_TESH_FACTORIES(tesh-msg-listen-async "thread;ucontext;raw" --setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR} --cd ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/listen_async.tesh)
--- /dev/null
+/* Bug report: https://github.com/mquinson/simgrid/issues/40
+ *
+ * Task.listen used to be on async mailboxes as it always returned false.
+ * This occures in Java and C, but is only tested here in C.
+ */
+
+#include <stdio.h>
+#include "simgrid/msg.h"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
+
+static int server(int argc, char *argv[])
+{
+ msg_task_t task = MSG_task_create("a", 0, 0, (char*)"Some data");
+ MSG_task_isend(task, "mailbox");
+
+ xbt_assert(MSG_task_listen("mailbox")); // True (1)
+ XBT_INFO("Task listen works on regular mailboxes");
+ task = NULL;
+ MSG_task_receive(&task, "mailbox");
+ xbt_assert(!strcmp("Some data", MSG_task_get_data(task)), "Data received: %s", (char*)MSG_task_get_data(task));
+ MSG_task_destroy(task);
+ XBT_INFO("Data successfully received from regular mailbox");
+
+ MSG_mailbox_set_async("mailbox2");
+ task = MSG_task_create("b", 0, 0, (char*)"More data");
+ MSG_task_isend(task, "mailbox2");
+
+ xbt_assert(MSG_task_listen("mailbox2")); // used to break.
+ XBT_INFO("Task listen works on asynchronous mailboxes");
+ task = NULL;
+ MSG_task_receive(&task, "mailbox2");
+ xbt_assert(!strcmp("More data", MSG_task_get_data(task)));
+ MSG_task_destroy(task);
+ XBT_INFO("Data successfully received from asynchronous mailbox");
+
+ return 0;
+}
+
+
+int main(int argc, char *argv[])
+{
+ MSG_init(&argc, argv);
+ xbt_assert(argc==2);
+ MSG_create_environment(argv[1]);
+ MSG_process_create("test", server, NULL, MSG_host_by_name("Tremblay"));
+ MSG_main();
+
+ return 0;
+}
--- /dev/null
+$ ./listen_async ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (1:test@Tremblay) Task listen works on regular mailboxes
+> [ 0.000195] (1:test@Tremblay) Data successfully received from regular mailbox
+> [ 0.000195] (1:test@Tremblay) Task listen works on asynchronous mailboxes
+> [ 0.000195] (1:test@Tremblay) Data successfully received from asynchronous mailbox
+> [ 0.000195] (0:maestro@) Variable 3 still in system when freing it: this may be a bug
teshsuite/msg/get_sender/CMakeLists.txt
teshsuite/msg/host_on_off/CMakeLists.txt
teshsuite/msg/host_on_off_processes/CMakeLists.txt
+ teshsuite/msg/listen_async/CMakeLists.txt
teshsuite/msg/pid/CMakeLists.txt
teshsuite/msg/process/CMakeLists.txt
teshsuite/msg/process_join/CMakeLists.txt