+ XBT_DEBUG("Cleanup process %s (%p), waiting action %p",
+ process->name, process, process->waiting_action);
+
+ SIMIX_process_on_exit_runall(process);
+
+ /* cancel non-blocking communications */
+ smx_action_t action;
+ while ((action = xbt_fifo_pop(process->comms))) {
+
+ /* make sure no one will finish the comm after this process is destroyed,
+ * because src_proc or dst_proc would be an invalid pointer */
+ SIMIX_comm_cancel(action);
+
+ if (action->comm.src_proc == process) {
+ XBT_DEBUG("Found an unfinished send comm %p (detached = %d), state %d, src = %p, dst = %p",
+ action, action->comm.detached, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
+ action->comm.src_proc = NULL;
+
+ /* I'm not supposed to destroy a detached comm from the sender side, */
+ if (!action->comm.detached)
+ SIMIX_comm_destroy(action);
+ else
+ XBT_DEBUG("Don't destroy it since it's a detached comm");
+
+ }
+ else if (action->comm.dst_proc == process){
+ XBT_DEBUG("Found an unfinished recv comm %p, state %d, src = %p, dst = %p",
+ action, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
+ action->comm.dst_proc = NULL;
+
+ if (action->comm.detached && action->comm.refcount == 1
+ && action->comm.src_proc != NULL) {
+ /* the comm will be freed right now, remove it from the sender */
+ xbt_fifo_remove(action->comm.src_proc->comms, action);
+ }
+ SIMIX_comm_destroy(action);
+ }
+ else {
+ xbt_die("Communication action %p is in my list but I'm not the sender "
+ "or the receiver", action);
+ }
+ }
+
+ xbt_swag_remove(process, simix_global->process_list);
+ xbt_swag_remove(process, SIMIX_host_priv(process->smx_host)->process_list);
+ xbt_swag_insert(process, simix_global->process_to_destroy);
+ process->context->iwannadie = 0;