Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simix] Do not deadlock when joining a process which is already dead
authorGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jun 2016 14:15:41 +0000 (16:15 +0200)
committerGabriel Corona <gabriel.corona@loria.fr>
Tue, 21 Jun 2016 14:18:24 +0000 (16:18 +0200)
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.

src/simix/smx_process.cpp
src/simix/smx_process_private.h

index de6db49..d4537ba 100644 (file)
@@ -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;
index 29e0756..d844aba 100644 (file)
@@ -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;