X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/74c1bf2b26c5a3aa0d8c29674dc12993e7c0de15..47e39aa9787af784b651e6be2ed219d0d40234fb:/src/simix/ActorImpl.cpp diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index 930d90e43e..a55a783f3b 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -73,8 +73,10 @@ void SIMIX_process_cleanup(smx_actor_t process) SIMIX_process_on_exit_runall(process); /* Unregister from the kill timer if any */ - if (process->kill_timer != nullptr) + if (process->kill_timer != nullptr) { SIMIX_timer_remove(process->kill_timer); + process->kill_timer = nullptr; + } xbt_os_mutex_acquire(simix_global->mutex); @@ -185,7 +187,7 @@ simgrid::s4u::Actor* ActorImpl::restart() // start the new process ActorImpl* actor = simix_global->create_process_function(arg.name.c_str(), std::move(arg.code), arg.data, arg.host, - arg.properties, nullptr); + arg.properties.get(), nullptr); if (arg.kill_time >= 0) simcall_process_set_kill_time(actor, arg.kill_time); if (arg.auto_restart) @@ -428,16 +430,10 @@ void SIMIX_process_detach() if (not context) xbt_die("Not a suitable context"); - simix_global->cleanup_process_function(context->process()); - - // Let maestro ignore we are still alive: - // xbt_swag_remove(context->process(), simix_global->process_list); - - // TODO, Remove from proces list: - // xbt_swag_remove(process, sg_host_simix(host)->process_list); - + auto process = context->process(); + simix_global->cleanup_process_function(process); context->attach_stop(); - // delete context; + delete process; } /** @@ -683,10 +679,9 @@ void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, do simcall->issuer->waiting_synchro = sync; } -static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* synchro) +static int SIMIX_process_join_finish(smx_process_exit_status_t status, smx_actor_t process, smx_activity_t sleep_act) { - simgrid::kernel::activity::SleepImpl* sleep = static_cast(synchro); - + simgrid::kernel::activity::SleepImpl* sleep = static_cast(sleep_act.get()); if (sleep->surf_sleep) { sleep->surf_sleep->cancel(); @@ -706,7 +701,8 @@ static int SIMIX_process_join_finish(smx_process_exit_status_t status, void* syn sleep->surf_sleep->unref(); sleep->surf_sleep = nullptr; } - // intrusive_ptr_release(process); // FIXME: We are leaking here. See comment in SIMIX_process_join() + intrusive_ptr_release(process); + intrusive_ptr_release(sleep_act.get()); return 0; } @@ -714,18 +710,16 @@ smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, doubl { smx_activity_t res = issuer->sleep(timeout); intrusive_ptr_add_ref(res.get()); - /* We are leaking the process here, but if we don't take the ref, we get a "use after free". - * The correct solution would be to derivate the type SynchroSleep into a SynchroProcessJoin, - * but the code is not clean enough for now for this. - * The C API should first be properly replaced with the C++ one, which is a fair amount of work. - */ intrusive_ptr_add_ref(process); SIMIX_process_on_exit(process, [](void*, void* arg) { - return simgrid::simix::kernelImmediate( - [&] { return SIMIX_process_join_finish(SMX_EXIT_SUCCESS, arg); }); + auto argp = static_cast*>(arg); + int res = simgrid::simix::kernelImmediate( + [&] { return SIMIX_process_join_finish(SMX_EXIT_SUCCESS, argp->first, argp->second); }); + delete argp; + return res; }, - &*res); + new std::pair(process, res)); return res; }