Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
forcefully kill exiting actors even if their host is not off
[simgrid.git] / src / kernel / actor / ActorImpl.cpp
index fc75399..c8640b4 100644 (file)
@@ -61,9 +61,13 @@ ActorImpl::ActorImpl(const simgrid::xbt::string& name, s4u::Host* host) : host_(
 
 ActorImpl::~ActorImpl()
 {
-  context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
-  simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_destruction(*ciface()); });
-  context_->iwannadie = true;
+  if (simix_global != nullptr && this != simix_global->maestro_process) {
+    if (context_.get() != nullptr) /* the actor was not start()ed yet. This happens if its host was initially off */
+      context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+    simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_destruction(*ciface()); });
+    if (context_.get() != nullptr)
+      context_->iwannadie = true;
+  }
 }
 
 /* Become an actor in the simulation
@@ -183,6 +187,10 @@ void ActorImpl::cleanup()
   }
 
   simix_global->mutex.unlock();
+
+  context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+  simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_termination(*ciface()); });
+  context_->iwannadie = true;
 }
 
 void ActorImpl::exit()
@@ -191,10 +199,6 @@ void ActorImpl::exit()
   suspended_          = false;
   exception_          = nullptr;
 
-  // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
-  if (not host_->is_on())
-    this->throw_exception(std::make_exception_ptr(ForcefulKillException("host failed")));
-
   /* destroy the blocking synchro if any */
   if (waiting_synchro != nullptr) {
     waiting_synchro->cancel();
@@ -217,6 +221,9 @@ void ActorImpl::exit()
 
     waiting_synchro = nullptr;
   }
+
+  // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
+  this->throw_exception(std::make_exception_ptr(ForcefulKillException(host_->is_on() ? "exited" : "host failed")));
 }
 
 void ActorImpl::kill(ActorImpl* actor)