Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
actor-exiting: Align the C test with the C++ one
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 6 May 2020 21:24:19 +0000 (23:24 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 6 May 2020 21:24:19 +0000 (23:24 +0200)
examples/c/actor-exiting/actor-exiting.c
examples/c/actor-exiting/actor-exiting.tesh

index d568802..330587d 100644 (file)
 #include <simgrid/actor.h>
 #include <simgrid/engine.h>
 #include <simgrid/host.h>
+#include <simgrid/mailbox.h>
 
 #include <xbt/asserts.h>
 #include <xbt/log.h>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_exiting, "Messages specific for this example");
 
-static int my_on_exit(XBT_ATTRIB_UNUSED int ignored1, XBT_ATTRIB_UNUSED void* ignored2)
+static int A_on_exit(XBT_ATTRIB_UNUSED int ignored1, XBT_ATTRIB_UNUSED void* ignored2)
 {
   XBT_INFO("I stop now");
   return 0;
 }
 
-static void actor_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+static void actorA_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
 {
   // Register a lambda function to be executed once it stops
-  sg_actor_on_exit(&my_on_exit, NULL);
+  sg_actor_on_exit(&A_on_exit, NULL);
 
-  sg_actor_execute(1e9);
+  sg_actor_sleep_for(1);
+}
+static void actorB_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+  sg_actor_sleep_for(2);
+}
+static int C_on_exit(int failed, XBT_ATTRIB_UNUSED void* ignored2)
+{
+  if (failed) {
+    XBT_INFO("I was killed!");
+    if (xbt_log_no_loc)
+      XBT_INFO("The backtrace would be displayed here if --log=no_loc would not have been passed");
+    else
+      xbt_backtrace_display_current();
+  } else
+    XBT_INFO("Exiting gracefully.");
+  return 0;
+}
+static void actorC_fun(XBT_ATTRIB_UNUSED int argc, XBT_ATTRIB_UNUSED char* argv[])
+{
+  // Register a lambda function to be executed once it stops
+  sg_actor_on_exit(&C_on_exit, NULL);
+
+  sg_actor_sleep_for(3);
+  XBT_INFO("And now, induce a deadlock by waiting for a message that will never come\n\n");
+  sg_mailbox_get(sg_mailbox_by_name("nobody"));
+  xbt_die("Receiving is not supposed to succeed when nobody is sending");
 }
 
 int main(int argc, char* argv[])
@@ -46,7 +73,9 @@ int main(int argc, char* argv[])
 
   simgrid_load_platform(argv[1]); /* - Load the platform description */
 
-  sg_actor_create("A", sg_host_by_name("Tremblay"), actor_fun, 0, NULL);
+  sg_actor_create("A", sg_host_by_name("Tremblay"), actorA_fun, 0, NULL);
+  sg_actor_create("B", sg_host_by_name("Fafard"), actorB_fun, 0, NULL);
+  sg_actor_create("C", sg_host_by_name("Ginette"), actorC_fun, 0, NULL);
 
   simgrid_run();
 
index adf57a8..613db5b 100644 (file)
@@ -1,4 +1,13 @@
 #!/usr/bin/env tesh
 
-$ ${bindir:=.}/c-actor-exiting ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
-> [ 10.194200] (A@Tremblay) I stop now
+$ ${bindir:=.}/c-actor-exiting ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n" --log=no_loc
+> [  1.000000] (A@Tremblay) I stop now
+> [  3.000000] (C@Ginette) And now, induce a deadlock by waiting for a message that will never come
+> 
+> 
+> [  3.000000] (maestro@) Oops! Deadlock or code not perfectly clean.
+> [  3.000000] (maestro@) 1 actors are still running, waiting for something.
+> [  3.000000] (maestro@) Legend of the following listing: "Actor <pid> (<name>@<host>): <status>"
+> [  3.000000] (maestro@) Actor 3 (C@Ginette): waiting for communication activity 0xdeadbeef () in state 0 to finish
+> [  3.000000] (C@Ginette) I was killed!
+> [  3.000000] (C@Ginette) The backtrace would be displayed here if --log=no_loc would not have been passed