+
+ while ((process = xbt_swag_extract(simix_global->process_to_destroy))) {
+ SIMIX_context_free(process->context);
+
+ /* Free the exception allocated at creation time */
+ free(process->running_ctx);
+ xbt_dict_free(&process->properties);
+
+ xbt_fifo_free(process->comms);
+
+ xbt_dynar_free(&process->on_exit);
+
+ free(process->name);
+ free(process);
+ }
+}
+
+/**
+ * \brief Creates and runs the maestro process
+ */
+void SIMIX_create_maestro_process()
+{
+ smx_process_t maestro = NULL;
+
+ /* Create maestro process and intilialize it */
+ maestro = xbt_new0(s_smx_process_t, 1);
+ maestro->pid = simix_process_maxpid++;
+ maestro->name = (char *) "";
+ maestro->running_ctx = xbt_new(xbt_running_ctx_t, 1);
+ XBT_RUNNING_CTX_INITIALIZE(maestro->running_ctx);
+ maestro->context = SIMIX_context_new(NULL, 0, NULL, NULL, maestro);
+ maestro->simcall.issuer = maestro;
+
+ simix_global->maestro_process = maestro;
+ return;
+}
+/**
+ * \brief Stops a process.
+ *
+ * Stops the process, execute all the registered on_exit functions,
+ * register it to the list of the process to restart if needed
+ * and stops its context.
+ */
+void SIMIX_process_stop(smx_process_t arg) {
+ /* 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
+ */
+ if (arg->auto_restart && !SIMIX_host_get_state(arg->smx_host)) {
+ SIMIX_host_add_auto_restart_process(arg->smx_host,arg->name,arg->code, arg->data,
+ sg_host_name(arg->smx_host),
+ arg->kill_time,
+ arg->argc,arg->argv,arg->properties,
+ arg->auto_restart);
+ }
+ XBT_DEBUG("Process %s (%s) is dead",arg->name,sg_host_name(arg->smx_host));
+ /* stop the context */
+ SIMIX_context_stop(arg->context);
+}
+
+/**
+ * \brief Same as SIMIX_process_create() but with only one argument (used by timers).
+ * This function frees the argument.
+ * \return the process created
+ */
+smx_process_t SIMIX_process_create_from_wrapper(smx_process_arg_t args) {
+
+ smx_process_t process;
+ simix_global->create_process_function(
+ &process,
+ args->name,
+ args->code,
+ args->data,
+ args->hostname,
+ args->kill_time,
+ args->argc,
+ args->argv,
+ args->properties,
+ args->auto_restart);
+ xbt_free(args);
+ return process;
+}
+
+
+void SIMIX_pre_process_create(smx_simcall_t simcall,
+ smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties,
+ int auto_restart){
+ return SIMIX_process_create(process, name, code, data, hostname,
+ kill_time, argc, argv, properties, auto_restart);
+}
+/**
+ * \brief Internal function to create a process.
+ *
+ * This function actually creates the process.
+ * It may be called when a SIMCALL_PROCESS_CREATE simcall occurs,
+ * or directly for SIMIX internal purposes. The sure thing is that it's called from maestro context.
+ *
+ * \return the process created
+ */
+void SIMIX_process_create(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties,
+ int auto_restart) {
+
+ *process = NULL;