Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix 'on_exit' preservation which failed when auto_restart was set first (FG#11).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 24 Apr 2019 08:21:17 +0000 (10:21 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 24 Apr 2019 08:39:46 +0000 (10:39 +0200)
The 'on_exit' vector is now shared between the ActorImpl and ProcessArg.

src/kernel/actor/ActorImpl.cpp
src/kernel/actor/ActorImpl.hpp
src/surf/HostImpl.cpp

index 99b32d2..86b8b59 100644 (file)
@@ -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<void(int, void
 void SIMIX_process_on_exit(smx_actor_t actor, const std::function<void(bool /*failed*/)>& 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. */
index 3394c36..caef390 100644 (file)
@@ -65,7 +65,9 @@ public:
   activity::ActivityImplPtr waiting_synchro = nullptr; /* the current blocking synchro if any */
   std::list<activity::ActivityImplPtr> comms;          /* the current non-blocking communication synchros */
   s_smx_simcall simcall;
-  std::vector<std::function<void(bool)>> on_exit; /* list of functions executed when the process dies */
+  /* list of functions executed when the process dies */
+  const std::shared_ptr<std::vector<std::function<void(bool)>>> on_exit =
+      std::make_shared<std::vector<std::function<void(bool)>>>();
 
   std::function<void()> code;
   simix::Timer* kill_timer = nullptr;
@@ -136,7 +138,8 @@ public:
   std::shared_ptr<const std::unordered_map<std::string, std::string>> properties = nullptr;
   bool auto_restart                                                        = false;
   bool daemon_                                                             = false;
-  std::vector<std::function<void(bool)>> on_exit; /* list of functions executed when the process dies */
+  /* list of functions executed when the process dies */
+  const std::shared_ptr<std::vector<std::function<void(bool)>>> on_exit;
 
   ProcessArg()                                                             = default;
 
index f2b102c..09d521b 100644 (file)
@@ -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)