X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/702d0b8f5973b3f1ce01e0f334842a5279fb17d9..2685dbb427cbe90685e23c1000d8b6670bb91750:/src/kernel/actor/ActorImpl.cpp diff --git a/src/kernel/actor/ActorImpl.cpp b/src/kernel/actor/ActorImpl.cpp index c31407c38c..c943038964 100644 --- a/src/kernel/actor/ActorImpl.cpp +++ b/src/kernel/actor/ActorImpl.cpp @@ -22,8 +22,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)"); -static unsigned long simix_process_maxpid = 0; - /** * @brief Returns the current agent. * @@ -53,16 +51,27 @@ namespace simgrid { namespace kernel { namespace actor { +static unsigned long maxpid = 0; +int get_maxpid() +{ + return maxpid; +} + ActorImpl::ActorImpl(const simgrid::xbt::string& name, s4u::Host* host) : host_(host), name_(name), piface_(this) { - pid_ = simix_process_maxpid++; + pid_ = maxpid++; simcall.issuer = this; } -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; +ActorImpl::~ActorImpl() +{ + 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 @@ -182,6 +191,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() @@ -190,10 +203,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(); @@ -216,6 +225,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) @@ -516,14 +528,14 @@ void create_maestro(const std::function& code) } // namespace kernel } // namespace simgrid -void SIMIX_process_detach() +void SIMIX_process_detach() // deprecated v3.25 { simgrid::kernel::actor::ActorImpl::detach(); } smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname, std::unordered_map* properties, - smx_actor_t /*parent_process*/) + smx_actor_t /*parent_process*/) // deprecated 3.25 { return simgrid::kernel::actor::ActorImpl::attach(name, data, sg_host_by_name(hostname), properties).get(); } @@ -542,11 +554,6 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t actor) /* If we are suspending ourselves, then just do not finish the simcall now */ } -int SIMIX_process_get_maxpid() -{ - return simix_process_maxpid; -} - int SIMIX_process_count() { return simix_global->process_list.size(); @@ -624,8 +631,14 @@ const std::vector& simgrid::simix::process_get_runnable() /** @brief Returns the process from PID. */ smx_actor_t SIMIX_process_from_PID(aid_t PID) { - auto actor = simix_global->process_list.find(PID); - return actor == simix_global->process_list.end() ? nullptr : actor->second; + auto item = simix_global->process_list.find(PID); + if (item == simix_global->process_list.end()) { + for (auto& a : simix_global->actors_to_destroy) + if (a.get_pid() == PID) + return &a; + return nullptr; // Not found, even in the trash + } + return item->second; } void SIMIX_process_on_exit(smx_actor_t actor, int_f_pvoid_pvoid_t fun, void* data)