Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make sure that ActorImpl::cleanup_from_kernel is called only once per actor, and...
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Sun, 13 Mar 2022 23:06:24 +0000 (00:06 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 14 Mar 2022 20:42:44 +0000 (21:42 +0100)
src/kernel/EngineImpl.cpp
src/kernel/actor/ActorImpl.cpp

index 76a938d..676413e 100644 (file)
@@ -467,11 +467,7 @@ actor::ActorImpl* EngineImpl::get_actor_by_pid(aid_t pid)
   if (item != actor_list_.end())
     return item->second;
 
-  // Search the trash
-  for (auto& a : actors_to_destroy_)
-    if (a.get_pid() == pid)
-      return &a;
-  return nullptr; // Not found, even in the trash
+  return nullptr; // Not found
 }
 
 void EngineImpl::remove_daemon(actor::ActorImpl* actor)
index 21acfce..e0129d4 100644 (file)
@@ -137,10 +137,12 @@ bool ActorImpl::is_maestro() const
 
 void ActorImpl::cleanup_from_kernel()
 {
-  xbt_assert(s4u::Actor::is_maestro(), "Cleanup_from_kernel called from '%s' on '%s'", ActorImpl::self()->get_cname(),
-             get_cname());
+  xbt_assert(s4u::Actor::is_maestro(), "Cleanup_from_kernel must be called in maestro context");
 
   auto* engine = EngineImpl::get_instance();
+  if (engine->get_actor_by_pid(get_pid()) == nullptr)
+    return; // Already cleaned
+
   engine->remove_actor(get_pid());
   if (host_ && host_actor_list_hook.is_linked())
     host_->get_impl()->remove_actor(this);
@@ -154,6 +156,7 @@ void ActorImpl::cleanup_from_kernel()
   }
 
   undaemonize();
+  s4u::Actor::on_termination(*get_ciface());
 
   while (not mailboxes_.empty())
     mailboxes_.back()->set_receiver(nullptr);
@@ -192,7 +195,7 @@ void ActorImpl::cleanup_from_self()
   }
 
   set_wannadie(false); // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
-  actor::simcall_answered([this] { s4u::Actor::on_termination(*get_ciface()); });
+  actor::simcall_answered([] {}); // This empty callback is mandatory even if it drives me nuts.
   set_wannadie();
 }