-/** \ingroup m_process_management
- * \brief Creates and runs a new #msg_process_t.
-
- * A constructor for #msg_process_t taking four arguments and returning the
- * corresponding object. The structure (and the corresponding thread) is
- * created, and put in the list of ready process.
- * \param name a name for the object. It is for user-level information
- and can be NULL.
- * \param code is a function describing the behavior of the process. It
- should then only use functions described in \ref
- m_process_management (to create a new #msg_process_t for example),
- in \ref m_host_management (only the read-only functions i.e. whose
- name contains the word get), in \ref m_task_management (to create
- or destroy some #msg_task_t for example) and in \ref
- msg_task_usage (to handle file transfers and task processing).
- * \param data a pointer to any data one may want to attach to the new
- object. It is for user-level information and can be NULL. It can
- be retrieved with the function \ref MSG_process_get_data.
- * \param host the location where the new process is executed.
- * \param argc first argument passed to \a code
- * \param argv second argument passed to \a code. WARNING, these strings are freed by the SimGrid kernel when the process exits, so they cannot be static nor shared between several processes.
- * \param properties list a properties defined for this process
- * \see msg_process_t
- * \return The new corresponding object.
- */
-msg_process_t MSG_process_create_with_environment(const char *name,
- xbt_main_func_t code,
- void *data, msg_host_t host,
- int argc, char **argv,
- xbt_dict_t properties)
-{
- xbt_assert(code != NULL && host != NULL, "Invalid parameters: host and code params must not be NULL");
- simdata_process_t simdata = xbt_new0(s_simdata_process_t, 1);
- msg_process_t process;
-
- /* Simulator data for MSG */
- simdata->waiting_action = NULL;
- simdata->waiting_task = NULL;
- simdata->m_host = host;
- simdata->argc = argc;
- simdata->argv = argv;
- simdata->data = data;
- simdata->last_errno = MSG_OK;
-
- /* The TRACE process is created before the SIMIX one
- * to avoid issues when SIMIX decides to start the new
- * process right now (before returning the flow control). */
- unsigned int next_pid = SIMIX_process_get_maxpid();
- TRACE_msg_process_create(name, next_pid, host);
-
- /* Let's create the process: SIMIX may decide to start it right now,
- * even before returning the flow control to us */
- process = simcall_process_create(name, code, simdata, sg_host_get_name(host), -1,
- argc, argv, properties,0);
-
- if (!process) {
- /* Undo everything we have just changed */
- xbt_free(simdata);
- return NULL;
- // FIXME: is the TRACE process destroyed in this case?
- }
- else {
- xbt_assert(next_pid == process->pid, "Bad trace pid hack");
- simcall_process_on_exit(process,(int_f_pvoid_pvoid_t)TRACE_msg_process_kill,process);
+/**
+ * @brief Creates and runs a new #msg_process_t.
+
+ * A constructor for #msg_process_t taking four arguments and returning the corresponding object. The structure (and
+ * the corresponding thread) is created, and put in the list of ready process.
+ * @param name a name for the object. It is for user-level information and can be nullptr.
+ * @param code is a function describing the behavior of the process.
+ * @param data a pointer to any data one may want to attach to the new object. It is for user-level information and
+ * can be nullptr. It can be retrieved with the function @ref MSG_process_get_data.
+ * @param host the location where the new process is executed.
+ * @param argc first argument passed to @a code
+ * @param argv second argument passed to @a code. WARNING, these strings are freed by the SimGrid kernel when the
+ * process exits, so they cannot be static nor shared between several processes.
+ * @param properties list a properties defined for this process
+ * @see msg_process_t
+ * @return The new corresponding object.
+ */
+msg_process_t MSG_process_create_with_environment(const char *name, xbt_main_func_t code, void *data, msg_host_t host,
+ int argc, char **argv, xbt_dict_t properties)
+{
+ xbt_assert(host != nullptr, "Invalid parameters: host param must not be nullptr");
+ simgrid::simix::ActorCode function;
+ if (code)
+ function = simgrid::xbt::wrap_main(code, argc, static_cast<const char* const*>(argv));
+
+ simgrid::s4u::ActorPtr actor;
+
+ try {
+ if (data != nullptr) {
+ actor = simgrid::s4u::Actor::init(std::move(name), host);
+ actor->extension<simgrid::msg::ActorUserData>()->set_user_data(data);
+ xbt_dict_cursor_t cursor = nullptr;
+ char* key;
+ char* value;
+ xbt_dict_foreach (properties, cursor, key, value)
+ actor->set_property(key, value);
+ actor->start(std::move(function));
+ } else
+ actor = simgrid::s4u::Actor::create(std::move(name), host, std::move(function));
+ } catch (simgrid::HostFailureException const&) {
+ xbt_die("Could not launch a new process on failed host %s.", host->get_cname());