Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
First bricks for auto_restart support in SIMIX/MSG.
[simgrid.git] / src / simix / smx_process.c
1 /* Copyright (c) 2007, 2008, 2009, 2010. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "smx_private.h"
8 #include "xbt/sysdep.h"
9 #include "xbt/log.h"
10 #include "xbt/dict.h"
11 #include "mc/mc.h"
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix,
14                                 "Logging specific to SIMIX (process)");
15
16 unsigned long simix_process_maxpid = 0;
17
18 /**
19  * \brief Returns the current agent.
20  *
21  * This functions returns the currently running SIMIX process.
22  *
23  * \return The SIMIX process
24  */
25 XBT_INLINE smx_process_t SIMIX_process_self(void)
26 {
27   smx_context_t self_context = SIMIX_context_self();
28
29   return self_context ? SIMIX_context_get_data(self_context) : NULL;
30 }
31
32 /**
33  * \brief Returns whether a process has pending asynchronous communications.
34  * \return true if there are asynchronous communications in this process
35  */
36 int SIMIX_process_has_pending_comms(smx_process_t process) {
37
38   return xbt_fifo_size(process->comms) > 0;
39 }
40
41 /**
42  * \brief Moves a process to the list of processes to destroy.
43  */
44 void SIMIX_process_cleanup(smx_process_t process)
45 {
46   XBT_DEBUG("Cleanup process %s (%p), waiting action %p",
47       process->name, process, process->waiting_action);
48
49   /* cancel non-blocking communications */
50   smx_action_t action;
51   while ((action = xbt_fifo_pop(process->comms))) {
52
53     /* make sure no one will finish the comm after this process is destroyed,
54      * because src_proc or dst_proc would be an invalid pointer */
55     SIMIX_comm_cancel(action);
56
57     if (action->comm.src_proc == process) {
58       XBT_DEBUG("Found an unfinished send comm %p (detached = %d), state %d, src = %p, dst = %p",
59           action, action->comm.detached, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
60       action->comm.src_proc = NULL;
61
62       if (action->comm.detached) {
63          if (action->comm.refcount == 0) {
64            XBT_DEBUG("Increase the refcount before destroying it since it's detached");
65            /* I'm not supposed to destroy a detached comm from the sender side,
66             * unless there is no receiver matching the rdv */
67            action->comm.refcount++;
68            SIMIX_comm_destroy(action);
69          }
70          else {
71            XBT_DEBUG("Don't destroy it since its refcount is %d", action->comm.refcount);
72          }
73       } else {
74         SIMIX_comm_destroy(action);
75       }
76     }
77     else if (action->comm.dst_proc == process){
78       XBT_DEBUG("Found an unfinished recv comm %p, state %d, src = %p, dst = %p",
79           action, (int)action->state, action->comm.src_proc, action->comm.dst_proc);
80       action->comm.dst_proc = NULL;
81
82       if (action->comm.detached && action->comm.refcount == 1
83           && action->comm.src_proc != NULL) {
84         /* the comm will be freed right now, remove it from the sender */
85         xbt_fifo_remove(action->comm.src_proc->comms, action);
86       }
87       SIMIX_comm_destroy(action);
88     }
89     else {
90       xbt_die("Communication action %p is in my list but I'm not the sender "
91           "or the receiver", action);
92     }
93   }
94
95   /*xbt_swag_remove(process, simix_global->process_to_run);*/
96   xbt_swag_remove(process, simix_global->process_list);
97   xbt_swag_remove(process, process->smx_host->process_list);
98   xbt_swag_insert(process, simix_global->process_to_destroy);
99   process->context->iwannadie = 0;
100 }
101
102 /** 
103  * Garbage collection
104  *
105  * Should be called some time to time to free the memory allocated for processes
106  * that have finished (or killed).
107  */
108 void SIMIX_process_empty_trash(void)
109 {
110   smx_process_t process = NULL;
111
112   while ((process = xbt_swag_extract(simix_global->process_to_destroy))) {
113     SIMIX_context_free(process->context);
114
115     /* Free the exception allocated at creation time */
116     free(process->running_ctx);
117     xbt_dict_free(&process->properties);
118
119     xbt_fifo_free(process->comms);
120
121     xbt_dynar_free(&process->on_exit);
122
123     free(process->name);
124     free(process);
125   }
126 }
127
128 /**
129  * \brief Creates and runs the maestro process
130  */
131 void SIMIX_create_maestro_process()
132 {
133   smx_process_t maestro = NULL;
134
135   /* Create maestro process and intilialize it */
136   maestro = xbt_new0(s_smx_process_t, 1);
137   maestro->pid = simix_process_maxpid++;
138   maestro->name = (char *) "";
139   maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
140   XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
141   maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
142   maestro->simcall.issuer = maestro;
143
144   simix_global->maestro_process = maestro;
145   return;
146 }
147 /**
148  * \brief Stops a process.
149  * Stops the process, execute all the registered on_exit functions
150  * and stops its context.
151  */
152 void SIMIX_process_stop(smx_process_t arg) {
153   /* execute the on_exit functions */
154   SIMIX_process_on_exit_runall(arg);
155   /* Add the process to the list of process to restart, only if
156    * the host is down
157    */
158   if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) {
159     SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data,
160                                         arg->smx_host->name,
161                                         arg->kill_time,
162                                         arg->argc,arg->argv,arg->properties,
163                                         arg->auto_restart);
164   }
165   /* stop the context */
166   SIMIX_context_stop(arg->context);
167 }
168
169 /**
170  * \brief Same as SIMIX_process_create() but with only one argument (used by timers).
171  * This function frees the argument.
172  * \return the process created
173  */
174 smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
175
176   smx_process_t process;
177   simix_global->create_process_function(
178       &process,
179       args->name,
180       args->code,
181       args->data,
182       args->hostname,
183       args->kill_time,
184       args->argc,
185       args->argv,
186       args->properties,
187       args->auto_restart);
188   xbt_free(args);
189   return process;
190 }
191
192 /**
193  * \brief Internal function to create a process.
194  *
195  * This function actually creates the process.
196  * It may be called when a SIMCALL_PROCESS_CREATE simcall occurs,
197  * or directly for SIMIX internal purposes. The sure thing is that it's called from maestro context.
198  *
199  * \return the process created
200  */
201 void SIMIX_process_create(smx_process_t *process,
202                           const char *name,
203                           xbt_main_func_t code,
204                           void *data,
205                           const char *hostname,
206                           double kill_time,
207                           int argc, char **argv,
208                           xbt_dict_t properties,
209                           int auto_restart) {
210
211   *process = NULL;
212   smx_host_t host = SIMIX_host_get_by_name(hostname);
213
214   XBT_DEBUG("Start process %s on host %s", name, hostname);
215
216   if (!SIMIX_host_get_state(host)) {
217     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name,
218           hostname);
219   }
220   else {
221     *process = xbt_new0(s_smx_process_t, 1);
222
223     xbt_assert(((code != NULL) && (host != NULL)), "Invalid parameters");
224
225     /* Process data */
226     (*process)->pid = simix_process_maxpid++;
227     (*process)->name = xbt_strdup(name);
228     (*process)->smx_host = host;
229     (*process)->data = data;
230     (*process)->comms = xbt_fifo_new();
231     (*process)->simcall.issuer = *process;
232     /* Process data for auto-restart */
233     (*process)->auto_restart = auto_restart;
234     (*process)->code = code;
235     (*process)->argc = argc;
236     (*process)->argv = argv;
237     (*process)->kill_time = kill_time;
238
239
240     XBT_VERB("Create context %s", (*process)->name);
241     (*process)->context = SIMIX_context_new(code, argc, argv,
242       simix_global->cleanup_process_function, *process);
243
244     (*process)->running_ctx = xbt_new(xbt_running_ctx_t, 1);
245     XBT_RUNNING_CTX_INITIALIZE((*process)->running_ctx);
246
247     /* Add properties */
248     (*process)->properties = properties;
249
250     /* Add the process to it's host process list */
251     xbt_swag_insert(*process, host->process_list);
252
253     XBT_DEBUG("Start context '%s'", (*process)->name);
254
255     /* Now insert it in the global process list and in the process to run list */
256     xbt_swag_insert(*process, simix_global->process_list);
257     XBT_DEBUG("Inserting %s(%s) in the to_run list", (*process)->name, host->name);
258     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, *process);
259   }
260
261   if (kill_time > SIMIX_get_clock()) {
262     if (simix_global->kill_process_function) {
263       XBT_DEBUG("Process %s(%s) will be kill at time %f", (*process)->name,
264           (*process)->smx_host->name, kill_time);
265       SIMIX_timer_set(kill_time, simix_global->kill_process_function, *process);
266     }
267   }
268 }
269
270 /**
271  * \brief Executes the processes from simix_global->process_to_run.
272  *
273  * The processes of simix_global->process_to_run are run (in parallel if
274  * possible).  On exit, simix_global->process_to_run is empty, and
275  * simix_global->process_that_ran contains the list of processes that just ran.
276  * The two lists are swapped so, be careful when using them before and after a
277  * call to this function.
278  */
279 void SIMIX_process_runall(void)
280 {
281   SIMIX_context_runall();
282
283   xbt_dynar_t tmp = simix_global->process_that_ran;
284   simix_global->process_that_ran = simix_global->process_to_run;
285   simix_global->process_to_run = tmp;
286   xbt_dynar_reset(simix_global->process_to_run);
287 }
288
289 /**
290  * \brief Internal function to kill a SIMIX process.
291  *
292  * This function may be called when a SIMCALL_PROCESS_KILL simcall occurs,
293  * or directly for SIMIX internal purposes.
294  *
295  * \param process poor victim
296  */
297 void SIMIX_process_kill(smx_process_t process) {
298
299   XBT_DEBUG("Killing process %s on %s", process->name, process->smx_host->name);
300
301   process->context->iwannadie = 1;
302   process->blocked = 0;
303   process->suspended = 0;
304   /* FIXME: set doexception to 0 also? */
305
306   /* destroy the blocking action if any */
307   if (process->waiting_action) {
308
309     switch (process->waiting_action->type) {
310
311       case SIMIX_ACTION_EXECUTE:          
312       case SIMIX_ACTION_PARALLEL_EXECUTE:
313         SIMIX_host_execution_destroy(process->waiting_action);
314         break;
315
316       case SIMIX_ACTION_COMMUNICATE:
317         xbt_fifo_remove(process->comms, process->waiting_action);
318         SIMIX_comm_destroy(process->waiting_action);
319         break;
320
321         case SIMIX_ACTION_SLEEP:
322           SIMIX_process_sleep_destroy(process->waiting_action);
323           break;
324
325         case SIMIX_ACTION_SYNCHRO:
326           SIMIX_synchro_stop_waiting(process, &process->simcall);
327           SIMIX_synchro_destroy(process->waiting_action);
328           break;
329
330         case SIMIX_ACTION_IO:
331           SIMIX_io_destroy(process->waiting_action);
332           break;
333     }
334   }
335   if(!xbt_dynar_member(simix_global->process_to_run, &(process)))
336     xbt_dynar_push_as(simix_global->process_to_run, smx_process_t, process);
337 }
338
339 /**
340  * \brief Kills all running processes.
341  * \param issuer this one will not be killed
342  */
343 void SIMIX_process_killall(smx_process_t issuer)
344 {
345   smx_process_t p = NULL;
346
347   while ((p = xbt_swag_extract(simix_global->process_list))) {
348     if (p != issuer) {
349       SIMIX_process_kill(p);
350     }
351   }
352
353   SIMIX_context_runall();
354
355   SIMIX_process_empty_trash();
356 }
357
358 void SIMIX_process_change_host(smx_process_t process,
359              smx_host_t dest)
360 {
361   xbt_assert((process != NULL), "Invalid parameters");
362   xbt_swag_remove(process, process->smx_host->process_list);
363   process->smx_host = dest;
364   xbt_swag_insert(process, dest->process_list);
365 }
366
367 void SIMIX_pre_process_change_host(smx_process_t process, smx_host_t dest)
368 {
369   process->new_host = dest;
370 }
371
372 void SIMIX_pre_process_suspend(smx_simcall_t simcall)
373 {
374   smx_process_t process = simcall->process_suspend.process;
375   smx_action_t action_suspend =
376       SIMIX_process_suspend(process, simcall->issuer);
377
378   if (process != simcall->issuer) {
379     SIMIX_simcall_answer(simcall);
380   } else {
381     xbt_fifo_push(action_suspend->simcalls, simcall);
382     process->waiting_action = action_suspend;
383     SIMIX_host_execution_suspend(process->waiting_action);
384   }
385   /* If we are suspending ourselves, then just do not finish the simcall now */
386 }
387
388 smx_action_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer)
389 {
390   xbt_assert((process != NULL), "Invalid parameters");
391
392   if (process->suspended) {
393     XBT_DEBUG("Process '%s' is already suspended", process->name);
394     return NULL;
395   }
396
397   process->suspended = 1;
398
399   /* If we are suspending another process, and it is waiting on an action,
400      suspend its action. */
401   if (process != issuer) {
402
403     if (process->waiting_action) {
404
405       switch (process->waiting_action->type) {
406
407         case SIMIX_ACTION_EXECUTE:
408         case SIMIX_ACTION_PARALLEL_EXECUTE:
409           SIMIX_host_execution_suspend(process->waiting_action);
410           break;
411
412         case SIMIX_ACTION_COMMUNICATE:
413           SIMIX_comm_suspend(process->waiting_action);
414           break;
415
416         case SIMIX_ACTION_SLEEP:
417           SIMIX_process_sleep_suspend(process->waiting_action);
418           break;
419
420         case SIMIX_ACTION_SYNCHRO:
421           /* Suspension is delayed to when the process is rescheduled. */
422           break;
423
424         default:
425           xbt_die("Internal error in SIMIX_process_suspend: unexpected action type %d",
426               (int)process->waiting_action->type);
427       }
428       return NULL;
429     } else {
430       /* Suspension is delayed to when the process is rescheduled. */
431       return NULL;
432     }
433   } else {
434     return SIMIX_host_execute("suspend", process->smx_host, 0.0, 1.0);
435   }
436 }
437
438 void SIMIX_process_resume(smx_process_t process, smx_process_t issuer)
439 {
440   xbt_assert((process != NULL), "Invalid parameters");
441
442   XBT_IN("process = %p, issuer = %p", process, issuer);
443
444   if(process->context->iwannadie) {
445     XBT_VERB("Ignoring request to suspend a process that is currently dying.");
446     return;
447   }
448
449   if(!process->suspended) return;
450   process->suspended = 0;
451
452   /* If we are resuming another process, resume the action it was waiting for
453      if any. Otherwise add it to the list of process to run in the next round. */
454   if (process != issuer) {
455
456     if (process->waiting_action) {
457
458       switch (process->waiting_action->type) {
459
460         case SIMIX_ACTION_EXECUTE:          
461         case SIMIX_ACTION_PARALLEL_EXECUTE:
462           SIMIX_host_execution_resume(process->waiting_action);
463           break;
464
465         case SIMIX_ACTION_COMMUNICATE:
466           SIMIX_comm_resume(process->waiting_action);
467           break;
468
469         case SIMIX_ACTION_SLEEP:
470           SIMIX_process_sleep_resume(process->waiting_action);
471           break;
472
473         case SIMIX_ACTION_SYNCHRO:
474           /* I cannot resume it now. This is delayed to when the process is rescheduled at
475            * the end of the synchro. */
476           break;
477
478         default:
479           xbt_die("Internal error in SIMIX_process_resume: unexpected action type %d",
480               (int)process->waiting_action->type);
481       }
482     }
483   } else XBT_WARN("Strange. Process %p is trying to resume himself.", issuer);
484
485   XBT_OUT();
486 }
487
488 int SIMIX_process_get_maxpid(void) {
489   return simix_process_maxpid;
490 }
491
492 int SIMIX_process_count(void)
493 {
494   return xbt_swag_size(simix_global->process_list);
495 }
496
497 void* SIMIX_process_self_get_data(smx_process_t self)
498 {
499   xbt_assert(self == SIMIX_process_self(), "This is not the current process");
500
501   if (!self) {
502     return NULL;
503   }
504   return SIMIX_process_get_data(self);
505 }
506
507 void SIMIX_process_self_set_data(smx_process_t self, void *data)
508 {
509   xbt_assert(self == SIMIX_process_self(), "This is not the current process");
510
511   SIMIX_process_set_data(self, data);
512 }
513
514 void* SIMIX_process_get_data(smx_process_t process)
515 {
516   return process->data;
517 }
518
519 void SIMIX_process_set_data(smx_process_t process, void *data)
520 {
521   process->data = data;
522 }
523
524 smx_host_t SIMIX_process_get_host(smx_process_t process)
525 {
526   return process->smx_host;
527 }
528
529 /* needs to be public and without simcall because it is called
530    by exceptions and logging events */
531 const char* SIMIX_process_self_get_name(void) {
532
533   smx_process_t process = SIMIX_process_self();
534   if (process == NULL || process == simix_global->maestro_process)
535     return "";
536
537   return SIMIX_process_get_name(process);
538 }
539
540 const char* SIMIX_process_get_name(smx_process_t process)
541 {
542   return process->name;
543 }
544
545 smx_process_t SIMIX_process_get_by_name(const char* name)
546 {
547   smx_process_t proc;
548
549   xbt_swag_foreach(proc, simix_global->process_list)
550   {
551     if(!strcmp(name, proc->name))
552       return proc;
553   }
554   return NULL;
555 }
556
557 int SIMIX_process_is_suspended(smx_process_t process)
558 {
559   return process->suspended;
560 }
561
562 xbt_dict_t SIMIX_process_get_properties(smx_process_t process)
563 {
564   return process->properties;
565 }
566
567 void SIMIX_pre_process_sleep(smx_simcall_t simcall)
568 {
569   if (MC_IS_ENABLED) {
570     MC_process_clock_add(simcall->issuer, simcall->process_sleep.duration);
571     simcall->process_sleep.result = SIMIX_DONE;
572     SIMIX_simcall_answer(simcall);
573     return;
574   }
575   smx_action_t action = SIMIX_process_sleep(simcall->issuer, simcall->process_sleep.duration);
576   xbt_fifo_push(action->simcalls, simcall);
577   simcall->issuer->waiting_action = action;
578 }
579
580 smx_action_t SIMIX_process_sleep(smx_process_t process, double duration)
581 {
582   smx_action_t action;
583   smx_host_t host = process->smx_host;
584
585   /* check if the host is active */
586   if (surf_workstation_model->extension.
587       workstation.get_state(host->host) != SURF_RESOURCE_ON) {
588     THROWF(host_error, 0, "Host %s failed, you cannot call this function",
589            host->name);
590   }
591
592   action = xbt_mallocator_get(simix_global->action_mallocator);
593   action->type = SIMIX_ACTION_SLEEP;
594   action->name = NULL;
595 #ifdef HAVE_TRACING
596   action->category = NULL;
597 #endif
598
599   action->sleep.host = host;
600   action->sleep.surf_sleep =
601       surf_workstation_model->extension.workstation.sleep(host->host, duration);
602
603   surf_workstation_model->action_data_set(action->sleep.surf_sleep, action);
604   XBT_DEBUG("Create sleep action %p", action);
605
606   return action;
607 }
608
609 void SIMIX_post_process_sleep(smx_action_t action)
610 {
611   smx_simcall_t simcall;
612   e_smx_state_t state;
613
614   while ((simcall = xbt_fifo_shift(action->simcalls))) {
615
616     switch(surf_workstation_model->action_state_get(action->sleep.surf_sleep)){
617       case SURF_ACTION_FAILED:
618         simcall->issuer->context->iwannadie = 1;
619         //SMX_EXCEPTION(simcall->issuer, host_error, 0, "Host failed");
620         break;
621
622       case SURF_ACTION_DONE:
623         state = SIMIX_DONE;
624         break;
625
626       default:
627         THROW_IMPOSSIBLE;
628         break;
629     }
630     if (surf_workstation_model->extension.
631         workstation.get_state(simcall->issuer->smx_host->host) != SURF_RESOURCE_ON) {
632       simcall->issuer->context->iwannadie = 1;
633     }
634     simcall->process_sleep.result = state;
635     simcall->issuer->waiting_action = NULL;
636     SIMIX_simcall_answer(simcall);
637
638   }
639   SIMIX_process_sleep_destroy(action);
640 }
641
642 void SIMIX_process_sleep_destroy(smx_action_t action)
643 {
644   XBT_DEBUG("Destroy action %p", action);
645   if (action->sleep.surf_sleep)
646     action->sleep.surf_sleep->model_type->action_unref(action->sleep.surf_sleep);
647   xbt_mallocator_release(simix_global->action_mallocator, action);
648 }
649
650 void SIMIX_process_sleep_suspend(smx_action_t action)
651 {
652   surf_workstation_model->suspend(action->sleep.surf_sleep);
653 }
654
655 void SIMIX_process_sleep_resume(smx_action_t action)
656 {
657   surf_workstation_model->resume(action->sleep.surf_sleep);
658 }
659
660 /** 
661  * \brief Calling this function makes the process to yield.
662  *
663  * Only the current process can call this function, giving back the control to
664  * maestro.
665  *
666  * \param self the current process
667  */
668 void SIMIX_process_yield(smx_process_t self)
669 {
670   XBT_DEBUG("Yield process '%s'", self->name);
671
672   /* Go into sleep and return control to maestro */
673   SIMIX_context_suspend(self->context);
674
675   /* Ok, maestro returned control to us */
676   XBT_DEBUG("Control returned to me: '%s'", self->name);
677
678   if (self->new_host) {
679     SIMIX_process_change_host(self, self->new_host);
680     self->new_host = NULL;
681   }
682
683   if (self->context->iwannadie){
684     XBT_DEBUG("I wanna die!");
685     SIMIX_process_stop(self);
686   }
687
688   if(self->suspended) {
689     xbt_assert(!self->doexception, "Gloups! This exception may be lost by subsequent calls.");
690     self->suspended = 0;
691     SIMIX_process_suspend(self,self);
692   }
693
694   if (self->doexception) {
695     XBT_DEBUG("Wait, maestro left me an exception");
696     self->doexception = 0;
697     SMX_THROW();
698   }
699 }
700
701 /* callback: context fetching */
702 xbt_running_ctx_t *SIMIX_process_get_running_context(void)
703 {
704   return SIMIX_process_self()->running_ctx;
705 }
706
707 /* callback: termination */
708 void SIMIX_process_exception_terminate(xbt_ex_t * e)
709 {
710   xbt_ex_display(e);
711   abort();
712 }
713
714 smx_context_t SIMIX_process_get_context(smx_process_t p) {
715   return p->context;
716 }
717
718 void SIMIX_process_set_context(smx_process_t p,smx_context_t c) {
719   p->context = c;
720 }
721
722 /**
723  * \brief Returns the list of processes to run.
724  */
725 xbt_dynar_t SIMIX_process_get_runnable(void)
726 {
727   return simix_global->process_to_run;
728 }
729
730 /**
731  * \brief Returns the process from PID.
732  */
733 smx_process_t SIMIX_process_from_PID(int PID)
734 {
735   smx_process_t proc;
736   xbt_swag_foreach(proc, simix_global->process_list)
737   {
738    if(proc->pid == PID)
739    return proc;
740   }
741   return NULL;
742 }
743
744 /** @brief returns a dynar containg all currently existing processes */
745 xbt_dynar_t SIMIX_processes_as_dynar(void) {
746   smx_process_t proc;
747   xbt_dynar_t res = xbt_dynar_new(sizeof(smx_process_t),NULL);
748   xbt_swag_foreach(proc, simix_global->process_list) {
749     xbt_dynar_push(res,&proc);
750   }
751   return res;
752 }
753 void SIMIX_process_on_exit_runall(smx_process_t process) {
754   s_smx_process_exit_fun_t exit_fun;
755
756   while (!xbt_dynar_is_empty(process->on_exit)) {
757     exit_fun = xbt_dynar_pop_as(process->on_exit,s_smx_process_exit_fun_t);
758     (exit_fun.fun)(exit_fun.arg);
759   }
760 }
761 void SIMIX_process_on_exit(smx_process_t process, int_f_pvoid_t fun, void *data) {
762   xbt_assert(process, "current process not found: are you in maestro context ?");
763
764   if (!process->on_exit) {
765     process->on_exit = xbt_dynar_new(sizeof(s_smx_process_exit_fun_t), NULL);
766   }
767
768   s_smx_process_exit_fun_t exit_fun = {fun, data};
769
770   xbt_dynar_push_as(process->on_exit,s_smx_process_exit_fun_t,exit_fun);
771 }
772 /**
773  * \brief Sets the auto-restart status of the process.
774  * If set to 1, the process will be automatically restarted when its host
775  * comes back.
776  */
777 void SIMIX_process_auto_restart_set(smx_process_t process, int auto_restart) {
778   process->auto_restart = auto_restart;
779 }