The 'on_exit' vector is now shared between the ActorImpl and ProcessArg.
// 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)
// 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);
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. */
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;
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;
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)