From: Gabriel Corona Date: Tue, 21 Jun 2016 14:15:41 +0000 (+0200) Subject: [simix] Do not deadlock when joining a process which is already dead X-Git-Tag: v3_14~897 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/a9caff9bc48c3653f3b3ae1ef0fda6a6699a8c06 [simix] Do not deadlock when joining a process which is already dead This was implemented by adding a callback SIMIX_process_on_exit() but if the process is already dead, the callback is never called. If the process is dead, we return directly to the calling process without any callback. --- diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index de6db49f08..d4537ba460 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -76,6 +76,7 @@ void SIMIX_process_cleanup(smx_process_t process) XBT_DEBUG("Cleanup process %s (%p), waiting synchro %p", process->name.c_str(), process, process->waiting_synchro); + process->finished = true; SIMIX_process_on_exit_runall(process); /* Unregister from the kill timer if any */ @@ -203,6 +204,7 @@ void SIMIX_maestro_create(void (*code)(void*), void* data) * and stops its context. */ void SIMIX_process_stop(smx_process_t arg) { + arg->finished = true; /* execute the on_exit functions */ SIMIX_process_on_exit_runall(arg); /* Add the process to the list of process to restart, only if the host is down */ @@ -751,6 +753,12 @@ xbt_dict_t SIMIX_process_get_properties(smx_process_t process) void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_process_t process, double timeout) { + if (process->finished) { + // The process is already finished, just wake up the process right now: + simcall_process_sleep__set__result(simcall, SIMIX_DONE); + SIMIX_simcall_answer(simcall); + return; + } smx_synchro_t sync = SIMIX_process_join(simcall->issuer, process, timeout); sync->simcalls.push_back(simcall); simcall->issuer->waiting_synchro = sync; diff --git a/src/simix/smx_process_private.h b/src/simix/smx_process_private.h index 29e0756fe6..d844aba45e 100644 --- a/src/simix/smx_process_private.h +++ b/src/simix/smx_process_private.h @@ -54,6 +54,7 @@ public: // TODO, pack them std::exception_ptr exception; + bool finished = false; bool blocked = false; bool suspended = false; bool auto_restart = false;