From: Martin Quinson Date: Mon, 12 Mar 2018 23:46:31 +0000 (+0100) Subject: factorize s4u-actor-kill and s4u-actor-kill-pid X-Git-Tag: v3.19~78^2~9 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/20a86cea43e842cf8ae78ed1bd3de29edf6a7409 factorize s4u-actor-kill and s4u-actor-kill-pid Add a kill by pid in s4u-actor-kill, and we're set. --- diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index 8782111271..64eb278e9a 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -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 index 3f1c42d583..0000000000 --- a/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.cpp +++ /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 - -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 index 79104cfbfe..0000000000 --- a/examples/s4u/actor-kill-pid/s4u-actor-kill-pid.tesh +++ /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 diff --git a/examples/s4u/actor-kill/s4u-actor-kill.cpp b/examples/s4u/actor-kill/s4u-actor-kill.cpp index 78658b9f7e..366364088e 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.cpp +++ b/examples/s4u/actor-kill/s4u-actor-kill.cpp @@ -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"); diff --git a/examples/s4u/actor-kill/s4u-actor-kill.tesh b/examples/s4u/actor-kill/s4u-actor-kill.tesh index 2e3145813c..eca4cd3996 100644 --- a/examples/s4u/actor-kill/s4u-actor-kill.tesh +++ b/examples/s4u/actor-kill/s4u-actor-kill.tesh @@ -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