Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factorize s4u-actor-kill and s4u-actor-kill-pid
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 12 Mar 2018 23:46:31 +0000 (00:46 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 12 Mar 2018 23:53:36 +0000 (00:53 +0100)
Add a kill by pid in s4u-actor-kill, and we're set.

examples/s4u/CMakeLists.txt
examples/s4u/actor-kill-pid/s4u-actor-kill-pid.cpp [deleted file]
examples/s4u/actor-kill-pid/s4u-actor-kill-pid.tesh [deleted file]
examples/s4u/actor-kill/s4u-actor-kill.cpp
examples/s4u/actor-kill/s4u-actor-kill.tesh

index 8782111..64eb278 100644 (file)
@@ -1,4 +1,4 @@
-foreach (example actor-create actor-daemon actor-join actor-kill actor-kill-pid
+foreach (example actor-create actor-daemon actor-join actor-kill
                  actor-lifetime actor-migration actor-suspend actor-yield
                  app-chainsend app-masterworker app-pingpong app-token-ring
                  async-wait async-waitany async-waitall
@@ -85,7 +85,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/replay-comm/s4u-re
                                   ${CMAKE_CURRENT_SOURCE_DIR}/replay-storage/s4u-replay-storage.txt
                                   ${CMAKE_CURRENT_SOURCE_DIR}/README.doc                                   PARENT_SCOPE)
 
-foreach(example actor-create actor-daemon actor-join actor-kill actor-kill-pid
+foreach(example actor-create actor-daemon actor-join actor-kill
                 actor-lifetime actor-migration actor-suspend actor-yield
                 app-bittorrent app-chainsend app-masterworker app-pingpong app-token-ring 
                 async-wait async-waitall async-waitany
diff --git a/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.cpp b/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.cpp
deleted file mode 100644 (file)
index 3f1c42d..0000000
+++ /dev/null
@@ -1,83 +0,0 @@
-/* Copyright (c) 2017-2018 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 <simgrid/s4u.hpp>
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_kill_pid, "Messages specific for this s4u example");
-
-static int on_exit(void*, void*)
-{
-  XBT_INFO("I have been killed!");
-  return 0;
-}
-
-static void victimA_fun()
-{
-  simgrid::s4u::this_actor::onExit(on_exit, nullptr);
-  XBT_INFO("Hello!");
-  XBT_INFO("Suspending myself");
-  simgrid::s4u::this_actor::suspend(); /* - Start by suspending itself */
-  XBT_INFO("OK, OK. Let's work");      /* - Then is resumed and start to execute a task */
-  simgrid::s4u::this_actor::execute(1e9);
-  XBT_INFO("Bye!"); /* - But will never reach the end of it */
-}
-
-static void victimB_fun()
-{
-  XBT_INFO("Terminate before being killed");
-}
-
-static void killer()
-{
-  XBT_INFO("Hello!"); /* - First start a victim process */
-  simgrid::s4u::ActorPtr victimA =
-      simgrid::s4u::Actor::createActor("victim A", simgrid::s4u::Host::by_name("Fafard"), victimA_fun);
-  simgrid::s4u::ActorPtr victimB =
-      simgrid::s4u::Actor::createActor("victim B", simgrid::s4u::Host::by_name("Jupiter"), victimB_fun);
-  simgrid::s4u::this_actor::sleep_for(10); /* - Wait for 10 seconds */
-
-  XBT_INFO("Resume the victim A"); /* - Resume it from its suspended state */
-  victimA->resume();
-  simgrid::s4u::this_actor::sleep_for(2);
-
-  aid_t pidA = victimA->getPid();
-  XBT_INFO("Kill the victim A (pid=%lu)", pidA); /* - and then kill it */
-  simgrid::s4u::Actor::kill(pidA);
-
-  aid_t pidB = victimB->getPid();
-  XBT_INFO("Kill victimB (pid=%lu), even if it's already dead", pidB); /* that's a no-op, there is no zombies in SimGrid */
-  try
-  {
-    simgrid::s4u::Actor::kill(pidB);
-  } catch (const std::runtime_error& e) {
-    XBT_DEBUG("Caught exception: %s", e.what());
-  }
-  simgrid::s4u::this_actor::sleep_for(1);
-
-  XBT_INFO("Killing everybody but myself");
-  simgrid::s4u::Actor::killAll();
-
-  aid_t pidMe = simgrid::s4u::this_actor::getPid();
-  XBT_INFO("OK, goodbye now. I commit a suicide (pid=%lu).", pidMe);
-  simgrid::s4u::Actor::kill(pidMe);
-
-  XBT_INFO("This line will never get displayed: I'm already dead since the previous line.");
-}
-
-int main(int argc, char* argv[])
-{
-  simgrid::s4u::Engine e(&argc, argv);
-  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
-
-  e.loadPlatform(argv[1]); /* - Load the platform description */
-  /* - Create and deploy killer process, that will create the victim actors  */
-  simgrid::s4u::Actor::createActor("killer", simgrid::s4u::Host::by_name("Tremblay"), killer);
-
-  e.run(); /* - Run the simulation */
-
-  XBT_INFO("Simulation time %g", e.getClock());
-
-  return 0;
-}
diff --git a/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.tesh b/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.tesh
deleted file mode 100644 (file)
index 79104cf..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env tesh
-
-$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-kill-pid ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
->[  0.000000] (killer@Tremblay) Hello!
->[  0.000000] (victim A@Fafard) Hello!
->[  0.000000] (victim A@Fafard) Suspending myself
->[  0.000000] (victim B@Jupiter) Terminate before being killed
->[ 10.000000] (killer@Tremblay) Resume the victim A
->[ 10.000000] (victim A@Fafard) OK, OK. Let's work
->[ 12.000000] (killer@Tremblay) Kill the victim A (pid=2)
->[ 12.000000] (victim A@Fafard) I have been killed!
->[ 12.000000] (killer@Tremblay) Kill victimB (pid=3), even if it's already dead
->[ 13.000000] (killer@Tremblay) Killing everybody but myself
->[ 13.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide (pid=1).
->[ 13.000000] (maestro@) Simulation time 13
index 78658b9..3663640 100644 (file)
@@ -43,10 +43,13 @@ static void killer()
   simgrid::s4u::this_actor::sleep_for(2);
 
   XBT_INFO("Kill the victim A"); /* - and then kill it */
-  victimA->kill();
+  simgrid::s4u::Actor::kill(victimA->getPid()); // Kill by PID is legit
+
+  simgrid::s4u::this_actor::sleep_for(1);
 
   XBT_INFO("Kill victimB, even if it's already dead"); /* that's a no-op, there is no zombies in SimGrid */
-  victimB->kill();
+  victimB->kill(); // the actor is automatically garbage-collected after this last reference
+
   simgrid::s4u::this_actor::sleep_for(1);
 
   XBT_INFO("Killing everybody but myself");
index 2e31458..eca4cd3 100644 (file)
@@ -9,7 +9,7 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-kill ${platfdir}/small_platform.xml "--l
 > [ 10.000000] (victim A@Fafard) OK, OK. Let's work
 > [ 12.000000] (killer@Tremblay) Kill the victim A
 > [ 12.000000] (victim A@Fafard) I have been killed!
-> [ 12.000000] (killer@Tremblay) Kill victimB, even if it's already dead
-> [ 13.000000] (killer@Tremblay) Killing everybody but myself
-> [ 13.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide.
-> [ 13.000000] (maestro@) Simulation time 13
+> [ 13.000000] (killer@Tremblay) Kill victimB, even if it's already dead
+> [ 14.000000] (killer@Tremblay) Killing everybody but myself
+> [ 14.000000] (killer@Tremblay) OK, goodbye now. I commit a suicide.
+> [ 14.000000] (maestro@) Simulation time 14