From 60b3f1d683ffdc0ec72d8ec1c3bbc57e53b44596 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 24 Apr 2019 10:21:17 +0200 Subject: [PATCH 1/1] Fix 'on_exit' preservation which failed when auto_restart was set first (FG#11). The 'on_exit' vector is now shared between the ActorImpl and ProcessArg. --- src/kernel/actor/ActorImpl.cpp | 11 ++++------- src/kernel/actor/ActorImpl.hpp | 7 +++++-- src/surf/HostImpl.cpp | 3 ++- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index 99b32d2897..86b8b59eff 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -141,11 +141,8 @@ void ActorImpl::cleanup() // Execute the termination callbacks bool failed = context_->iwannadie; - while (not on_exit.empty()) { - auto exit_fun = on_exit.back(); - on_exit.pop_back(); - exit_fun(failed); - } + for (auto exit_fun = on_exit->crbegin(); exit_fun != on_exit->crend(); ++exit_fun) + (*exit_fun)(failed); /* cancel non-blocking activities */ for (auto activity : comms) @@ -333,7 +330,7 @@ s4u::Actor* ActorImpl::restart() // start the new actor ActorImplPtr actor = ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr); - actor->on_exit = std::move(arg.on_exit); + *actor->on_exit = std::move(*arg.on_exit); actor->set_kill_time(arg.kill_time); actor->set_auto_restart(arg.auto_restart); @@ -651,7 +648,7 @@ void SIMIX_process_on_exit(smx_actor_t actor, const std::function& fun) { xbt_assert(actor, "current process not found: are you in maestro context ?"); - actor->on_exit.emplace_back(fun); + actor->on_exit->emplace_back(fun); } /** @brief Restart a process, starting it again from the beginning. */ diff --git a/src/kernel/actor/ActorImpl.hpp b/src/kernel/actor/ActorImpl.hpp index 3394c36c16..caef390209 100644 --- a/src/kernel/actor/ActorImpl.hpp +++ b/src/kernel/actor/ActorImpl.hpp @@ -65,7 +65,9 @@ public: activity::ActivityImplPtr waiting_synchro = nullptr; /* the current blocking synchro if any */ std::list comms; /* the current non-blocking communication synchros */ s_smx_simcall simcall; - std::vector> on_exit; /* list of functions executed when the process dies */ + /* list of functions executed when the process dies */ + const std::shared_ptr>> on_exit = + std::make_shared>>(); std::function code; simix::Timer* kill_timer = nullptr; @@ -136,7 +138,8 @@ public: std::shared_ptr> properties = nullptr; bool auto_restart = false; bool daemon_ = false; - std::vector> on_exit; /* list of functions executed when the process dies */ + /* list of functions executed when the process dies */ + const std::shared_ptr>> on_exit; ProcessArg() = default; diff --git a/src/surf/HostImpl.cpp b/src/surf/HostImpl.cpp index f2b102c987..09d521b66f 100644 --- a/src/surf/HostImpl.cpp +++ b/src/surf/HostImpl.cpp @@ -105,7 +105,8 @@ void HostImpl::turn_on() XBT_DEBUG("Booting Actor %s(%s) right now", arg->name.c_str(), arg->host->get_cname()); simgrid::kernel::actor::ActorImplPtr actor = simgrid::kernel::actor::ActorImpl::create( arg->name.c_str(), arg->code, nullptr, arg->host, arg->properties.get(), nullptr); - actor->on_exit = arg->on_exit; + if (arg->on_exit) + *actor->on_exit = *arg->on_exit; if (arg->kill_time >= 0) actor->set_kill_time(arg->kill_time); if (arg->auto_restart) -- 2.20.1