1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/Exception.hpp"
8 #include "simgrid/s4u/Actor.hpp"
9 #include "simgrid/s4u/Exec.hpp"
10 #include "smx_private.hpp"
11 #include "src/kernel/activity/CommImpl.hpp"
12 #include "src/kernel/activity/ExecImpl.hpp"
13 #include "src/kernel/activity/IoImpl.hpp"
14 #include "src/kernel/activity/SleepImpl.hpp"
15 #include "src/kernel/activity/SynchroRaw.hpp"
16 #include "src/mc/mc_replay.hpp"
17 #include "src/mc/remote/Client.hpp"
18 #include "src/simix/smx_host_private.hpp"
19 #include "src/simix/smx_io_private.hpp"
20 #include "src/simix/smx_synchro_private.hpp"
21 #include "src/surf/HostImpl.hpp"
22 #include "src/surf/cpu_interface.hpp"
24 #include <boost/range/algorithm.hpp>
26 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
28 static unsigned long simix_process_maxpid = 0;
31 * @brief Returns the current agent.
33 * This functions returns the currently running SIMIX process.
35 * @return The SIMIX process
37 smx_actor_t SIMIX_process_self()
39 smx_context_t self_context = simgrid::kernel::context::Context::self();
41 return (self_context != nullptr) ? self_context->get_actor() : nullptr;
45 * @brief Returns whether a process has pending asynchronous communications.
46 * @return true if there are asynchronous communications in this process
48 int SIMIX_process_has_pending_comms(smx_actor_t process) {
50 return process->comms.size() > 0;
54 * @brief Moves a process to the list of processes to destroy.
56 void SIMIX_process_cleanup(smx_actor_t process)
58 XBT_DEBUG("Cleanup process %s (%p), waiting synchro %p", process->get_cname(), process,
59 process->waiting_synchro.get());
61 simix_global->mutex.lock();
63 simix_global->process_list.erase(process->pid_);
64 if (process->host_ && process->host_process_list_hook.is_linked())
65 simgrid::xbt::intrusive_erase(process->host_->pimpl_->process_list_, *process);
66 if (not process->smx_destroy_list_hook.is_linked()) {
68 xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, process);
70 simix_global->process_to_destroy.push_back(*process);
72 process->context_->iwannadie = false;
74 simix_global->mutex.unlock();
80 * Should be called some time to time to free the memory allocated for processes that have finished (or killed).
82 void SIMIX_process_empty_trash()
84 while (not simix_global->process_to_destroy.empty()) {
85 smx_actor_t process = &simix_global->process_to_destroy.front();
86 simix_global->process_to_destroy.pop_front();
87 XBT_DEBUG("Getting rid of %p",process);
88 intrusive_ptr_release(process);
91 xbt_dynar_reset(simix_global->dead_actors_vector);
99 ActorImpl::ActorImpl(simgrid::xbt::string name, simgrid::s4u::Host* host) : name_(name), host_(host), piface_(this)
101 pid_ = simix_process_maxpid++;
102 simcall.issuer = this;
105 ActorImpl::~ActorImpl()
107 delete this->context_;
110 void ActorImpl::set_kill_time(double kill_time)
112 if (kill_time <= SIMIX_get_clock())
114 XBT_DEBUG("Set kill time %f for process %s@%s", kill_time, get_cname(), host_->get_cname());
115 kill_timer = SIMIX_timer_set(kill_time, [this] {
116 SIMIX_process_kill(this, nullptr);
117 kill_timer = nullptr;
121 static void dying_daemon(int /*exit_status*/, void* data)
123 std::vector<ActorImpl*>* vect = &simix_global->daemons;
125 auto it = std::find(vect->begin(), vect->end(), static_cast<ActorImpl*>(data));
126 xbt_assert(it != vect->end(), "The dying daemon is not a daemon after all. Please report that bug.");
128 /* Don't move the whole content since we don't really care about the order */
129 std::swap(*it, vect->back());
133 /** This process will be terminated automatically when the last non-daemon process finishes */
134 void ActorImpl::daemonize()
138 simix_global->daemons.push_back(this);
139 SIMIX_process_on_exit(this, dying_daemon, this);
143 simgrid::s4u::Actor* ActorImpl::restart()
145 XBT_DEBUG("Restarting process %s on %s", get_cname(), host_->get_cname());
147 // retrieve the arguments of the old process
148 simgrid::kernel::actor::ProcessArg arg = ProcessArg(host_, this);
150 // kill the old process
151 SIMIX_process_kill(this, (this == simix_global->maestro_process) ? this : SIMIX_process_self());
153 // start the new process
155 ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr);
156 actor->set_kill_time(arg.kill_time);
157 actor->set_auto_restart(arg.auto_restart);
159 return actor->ciface();
162 smx_activity_t ActorImpl::suspend(ActorImpl* issuer)
165 XBT_DEBUG("Actor '%s' is already suspended", get_cname());
171 /* If we are suspending another actor that is waiting on a sync, suspend its synchronization. */
172 if (this != issuer) {
174 waiting_synchro->suspend();
175 /* If the other actor is not waiting, its suspension is delayed to when the actor is rescheduled. */
179 return activity::ExecImplPtr(new activity::ExecImpl("suspend", "", nullptr, this->host_))->start(0.0, 1.0, 0.0);
183 void ActorImpl::resume()
185 XBT_IN("process = %p", this);
187 if (context_->iwannadie) {
188 XBT_VERB("Ignoring request to suspend an actor that is currently dying.");
196 /* resume the synchronization that was blocking the resumed actor. */
198 waiting_synchro->resume();
203 smx_activity_t ActorImpl::sleep(double duration)
206 throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
207 XBT_THROW_POINT, std::string("Host ") + std::string(host_->get_cname()) + " failed, you cannot sleep there.")));
209 simgrid::kernel::activity::SleepImpl* synchro = new simgrid::kernel::activity::SleepImpl();
210 synchro->host = host_;
211 synchro->surf_action_ = host_->pimpl_cpu->sleep(duration);
212 synchro->surf_action_->set_data(synchro);
213 XBT_DEBUG("Create sleep synchronization %p", synchro);
218 void ActorImpl::throw_exception(std::exception_ptr e)
225 /* cancel the blocking synchro if any */
226 if (waiting_synchro) {
228 simgrid::kernel::activity::ExecImplPtr exec =
229 boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(waiting_synchro);
230 if (exec != nullptr && exec->surf_action_)
231 exec->surf_action_->cancel();
233 simgrid::kernel::activity::CommImplPtr comm =
234 boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(waiting_synchro);
235 if (comm != nullptr) {
240 simgrid::kernel::activity::SleepImplPtr sleep =
241 boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(waiting_synchro);
242 if (sleep != nullptr) {
243 SIMIX_process_sleep_destroy(waiting_synchro);
244 if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), this) ==
245 end(simix_global->process_to_run) &&
246 this != SIMIX_process_self()) {
247 XBT_DEBUG("Inserting %s in the to_run list", get_cname());
248 simix_global->process_to_run.push_back(this);
252 simgrid::kernel::activity::RawImplPtr raw =
253 boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(waiting_synchro);
254 if (raw != nullptr) {
255 SIMIX_synchro_stop_waiting(this, &simcall);
258 simgrid::kernel::activity::IoImplPtr io =
259 boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(waiting_synchro);
264 waiting_synchro = nullptr;
267 void ActorImpl::set_host(sg_host_t dest)
269 simgrid::xbt::intrusive_erase(host_->pimpl_->process_list_, *this);
271 dest->pimpl_->process_list_.push_back(*this);
274 ActorImplPtr ActorImpl::create(std::string name, simgrid::simix::ActorCode code, void* data, simgrid::s4u::Host* host,
275 std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_actor)
278 XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
280 if (host->is_off()) {
281 XBT_WARN("Cannot launch actor '%s' on failed host '%s'", name.c_str(), host->get_cname());
285 ActorImpl* actor = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(name), host);
287 xbt_assert(code && host != nullptr, "Invalid parameters");
289 actor->set_user_data(data);
292 if (parent_actor != nullptr)
293 actor->ppid_ = parent_actor->pid_;
295 XBT_VERB("Create context %s", actor->get_cname());
296 actor->context_ = SIMIX_context_new(std::move(code), &SIMIX_process_cleanup, actor);
299 if (properties != nullptr)
300 for (auto const& kv : *properties)
301 actor->set_property(kv.first, kv.second);
303 /* Add the process to its host's process list */
304 host->pimpl_->process_list_.push_back(*actor);
306 XBT_DEBUG("Start context '%s'", actor->get_cname());
308 /* Now insert it in the global process list and in the process to run list */
309 simix_global->process_list[actor->pid_] = actor;
310 XBT_DEBUG("Inserting %s(%s) in the to_run list", actor->get_cname(), host->get_cname());
311 simix_global->process_to_run.push_back(actor);
312 intrusive_ptr_add_ref(actor);
314 /* The on_creation() signal must be delayed until there, where the pid and everything is set */
315 simgrid::s4u::Actor::on_creation(actor->iface());
317 return ActorImplPtr(actor);
320 void create_maestro(simgrid::simix::ActorCode code)
322 /* Create maestro process and initialize it */
323 smx_actor_t maestro = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(""), /*host*/ nullptr);
326 maestro->context_ = SIMIX_context_new(simgrid::simix::ActorCode(), nullptr, maestro);
328 maestro->context_ = simix_global->context_factory->create_maestro(code, maestro);
331 maestro->simcall.issuer = maestro;
332 simix_global->maestro_process = maestro;
336 } // namespace kernel
339 smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname,
340 std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_process)
342 // This is mostly a copy/paste from SIMIX_process_new(),
343 // it'd be nice to share some code between those two functions.
345 sg_host_t host = sg_host_by_name(hostname);
346 XBT_DEBUG("Attach process %s on host '%s'", name, hostname);
348 if (host->is_off()) {
349 XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, hostname);
353 smx_actor_t actor = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(name), host);
355 actor->set_user_data(data);
356 actor->code = nullptr;
358 if (parent_process != nullptr)
359 actor->ppid_ = parent_process->pid_;
361 XBT_VERB("Create context %s", actor->get_cname());
362 xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
363 actor->context_ = simix_global->context_factory->attach(&SIMIX_process_cleanup, actor);
366 if (properties != nullptr)
367 for (auto const& kv : *properties)
368 actor->set_property(kv.first, kv.second);
370 /* Add the process to it's host process list */
371 host->pimpl_->process_list_.push_back(*actor);
373 /* Now insert it in the global process list and in the process to run list */
374 simix_global->process_list[actor->pid_] = actor;
375 XBT_DEBUG("Inserting %s(%s) in the to_run list", actor->get_cname(), host->get_cname());
376 simix_global->process_to_run.push_back(actor);
377 intrusive_ptr_add_ref(actor);
379 auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(actor->context_);
380 xbt_assert(nullptr != context, "Not a suitable context");
381 context->attach_start();
383 /* The on_creation() signal must be delayed until there, where the pid and everything is set */
384 simgrid::s4u::ActorPtr tmp = actor->iface(); // Passing this directly to on_creation will lead to crashes
385 simgrid::s4u::Actor::on_creation(tmp);
390 void SIMIX_process_detach()
392 auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(simgrid::kernel::context::Context::self());
393 if (context == nullptr)
394 xbt_die("Not a suitable context");
396 SIMIX_process_cleanup(context->get_actor());
397 context->attach_stop();
401 * @brief Executes the processes from simix_global->process_to_run.
403 * The processes of simix_global->process_to_run are run (in parallel if
404 * possible). On exit, simix_global->process_to_run is empty, and
405 * simix_global->process_that_ran contains the list of processes that just ran.
406 * The two lists are swapped so, be careful when using them before and after a
407 * call to this function.
409 void SIMIX_process_runall()
411 SIMIX_context_runall();
413 simix_global->process_to_run.swap(simix_global->process_that_ran);
414 simix_global->process_to_run.clear();
418 * @brief Internal function to kill a SIMIX process.
420 * This function may be called when a SIMCALL_PROCESS_KILL simcall occurs,
421 * or directly for SIMIX internal purposes.
423 * @param actor poor victim
424 * @param issuer the actor which has sent the PROCESS_KILL. Important to not schedule twice the same actor.
426 void SIMIX_process_kill(smx_actor_t actor, smx_actor_t issuer)
429 if (actor->finished_) {
430 XBT_DEBUG("Ignoring request to kill process %s@%s that is already dead", actor->get_cname(),
431 actor->host_->get_cname());
435 XBT_DEBUG("Actor '%s'@%s is killing actor '%s'@%s", issuer == nullptr ? "(null)" : issuer->get_cname(),
436 (issuer == nullptr || issuer->host_ == nullptr ? "(null)" : issuer->host_->get_cname()), actor->get_cname(),
437 actor->host_->get_cname());
439 actor->context_->iwannadie = true;
440 actor->blocked_ = false;
441 actor->suspended_ = false;
442 actor->exception = nullptr;
444 // Forcefully kill the actor if its host is turned off. Not an HostFailureException because you should not survive that
445 if (actor->host_->is_off())
446 actor->throw_exception(std::make_exception_ptr(simgrid::kernel::context::StopRequest("host failed")));
448 /* destroy the blocking synchro if any */
449 if (actor->waiting_synchro != nullptr) {
451 simgrid::kernel::activity::ExecImplPtr exec =
452 boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(actor->waiting_synchro);
453 simgrid::kernel::activity::CommImplPtr comm =
454 boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(actor->waiting_synchro);
455 simgrid::kernel::activity::SleepImplPtr sleep =
456 boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
457 simgrid::kernel::activity::RawImplPtr raw =
458 boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(actor->waiting_synchro);
459 simgrid::kernel::activity::IoImplPtr io =
460 boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(actor->waiting_synchro);
462 if (exec != nullptr) {
463 if (exec->surf_action_) {
464 exec->surf_action_->cancel();
465 exec->surf_action_->unref();
466 exec->surf_action_ = nullptr;
468 } else if (comm != nullptr) {
469 actor->comms.remove(actor->waiting_synchro);
471 // Remove first occurrence of &process->simcall:
472 auto i = boost::range::find(actor->waiting_synchro->simcalls_, &actor->simcall);
473 if (i != actor->waiting_synchro->simcalls_.end())
474 actor->waiting_synchro->simcalls_.remove(&actor->simcall);
475 } else if (sleep != nullptr) {
476 if (sleep->surf_action_)
477 sleep->surf_action_->cancel();
479 } else if (raw != nullptr) {
480 SIMIX_synchro_stop_waiting(actor, &actor->simcall);
482 } else if (io != nullptr) {
485 simgrid::kernel::activity::ActivityImplPtr activity = actor->waiting_synchro;
486 xbt_die("Activity %s is of unknown type %s", activity->name_.c_str(),
487 simgrid::xbt::demangle(typeid(activity).name()).get());
490 actor->waiting_synchro = nullptr;
492 if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), actor) ==
493 end(simix_global->process_to_run) &&
495 XBT_DEBUG("Inserting %s in the to_run list", actor->get_cname());
496 simix_global->process_to_run.push_back(actor);
500 /** @deprecated When this function gets removed, also remove the xbt_ex class, that is only there to help users to
502 void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const char* msg)
504 SMX_EXCEPTION(actor, cat, value, msg);
506 if (actor->suspended_)
509 /* cancel the blocking synchro if any */
510 if (actor->waiting_synchro) {
512 simgrid::kernel::activity::ExecImplPtr exec =
513 boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(actor->waiting_synchro);
514 if (exec != nullptr && exec->surf_action_)
515 exec->surf_action_->cancel();
517 simgrid::kernel::activity::CommImplPtr comm =
518 boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(actor->waiting_synchro);
519 if (comm != nullptr) {
520 actor->comms.remove(comm);
524 simgrid::kernel::activity::SleepImplPtr sleep =
525 boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
526 if (sleep != nullptr) {
527 SIMIX_process_sleep_destroy(actor->waiting_synchro);
528 if (std::find(begin(simix_global->process_to_run), end(simix_global->process_to_run), actor) ==
529 end(simix_global->process_to_run) &&
530 actor != SIMIX_process_self()) {
531 XBT_DEBUG("Inserting %s in the to_run list", actor->get_cname());
532 simix_global->process_to_run.push_back(actor);
536 simgrid::kernel::activity::RawImplPtr raw =
537 boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(actor->waiting_synchro);
538 if (raw != nullptr) {
539 SIMIX_synchro_stop_waiting(actor, &actor->simcall);
542 simgrid::kernel::activity::IoImplPtr io =
543 boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(actor->waiting_synchro);
548 actor->waiting_synchro = nullptr;
552 * @brief Kills all running processes.
553 * @param issuer this one will not be killed
555 void SIMIX_process_killall(smx_actor_t issuer)
557 for (auto const& kv : simix_global->process_list)
558 if (kv.second != issuer)
559 SIMIX_process_kill(kv.second, issuer);
563 void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t actor)
565 smx_activity_t sync_suspend = actor->suspend(simcall->issuer);
567 if (actor != simcall->issuer) {
568 SIMIX_simcall_answer(simcall);
570 sync_suspend->simcalls_.push_back(simcall);
571 actor->waiting_synchro = sync_suspend;
572 actor->waiting_synchro->suspend();
574 /* If we are suspending ourselves, then just do not finish the simcall now */
577 int SIMIX_process_get_maxpid() {
578 return simix_process_maxpid;
581 int SIMIX_process_count()
583 return simix_global->process_list.size();
586 void* SIMIX_process_self_get_data()
588 smx_actor_t self = SIMIX_process_self();
590 if (self == nullptr) {
593 return self->get_user_data();
596 void SIMIX_process_self_set_data(void *data)
598 SIMIX_process_self()->set_user_data(data);
602 /* needs to be public and without simcall because it is called
603 by exceptions and logging events */
604 const char* SIMIX_process_self_get_name() {
606 smx_actor_t process = SIMIX_process_self();
607 if (process == nullptr || process == simix_global->maestro_process)
610 return process->get_cname();
613 void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, double timeout)
615 if (process->finished_) {
616 // The joined process is already finished, just wake up the issuer process right away
617 simcall_process_sleep__set__result(simcall, SIMIX_DONE);
618 SIMIX_simcall_answer(simcall);
621 smx_activity_t sync = SIMIX_process_join(simcall->issuer, process, timeout);
622 sync->simcalls_.push_back(simcall);
623 simcall->issuer->waiting_synchro = sync;
626 smx_activity_t SIMIX_process_join(smx_actor_t issuer, smx_actor_t process, double timeout)
628 smx_activity_t res = issuer->sleep(timeout);
629 intrusive_ptr_add_ref(res.get());
630 SIMIX_process_on_exit(process,
632 auto sleep = static_cast<simgrid::kernel::activity::SleepImpl*>(arg);
633 if (sleep->surf_action_)
634 sleep->surf_action_->finish(simgrid::kernel::resource::Action::State::FINISHED);
635 intrusive_ptr_release(sleep);
641 void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration)
643 if (MC_is_active() || MC_record_replay_is_active()) {
644 MC_process_clock_add(simcall->issuer, duration);
645 simcall_process_sleep__set__result(simcall, SIMIX_DONE);
646 SIMIX_simcall_answer(simcall);
649 smx_activity_t sync = simcall->issuer->sleep(duration);
650 sync->simcalls_.push_back(simcall);
651 simcall->issuer->waiting_synchro = sync;
654 void SIMIX_process_sleep_destroy(smx_activity_t synchro)
656 XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
657 simgrid::kernel::activity::SleepImplPtr sleep =
658 boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(synchro);
660 if (sleep->surf_action_) {
661 sleep->surf_action_->unref();
662 sleep->surf_action_ = nullptr;
667 * @brief Calling this function makes the process to yield.
669 * Only the current process can call this function, giving back the control to maestro.
671 * @param self the current process
673 void SIMIX_process_yield(smx_actor_t self)
675 XBT_DEBUG("Yield actor '%s'", self->get_cname());
677 /* Go into sleep and return control to maestro */
678 self->context_->suspend();
680 /* Ok, maestro returned control to us */
681 XBT_DEBUG("Control returned to me: '%s'", self->get_cname());
683 if (self->context_->iwannadie) {
685 XBT_DEBUG("Process %s@%s is dead", self->get_cname(), self->host_->get_cname());
686 // throw simgrid::kernel::context::StopRequest(); Does not seem to properly kill the actor
687 self->context_->stop();
691 if (self->suspended_) {
692 XBT_DEBUG("Hey! I'm suspended.");
693 xbt_assert(self->exception != nullptr, "Gasp! This exception may be lost by subsequent calls.");
694 self->suspended_ = false;
698 if (self->exception != nullptr) {
699 XBT_DEBUG("Wait, maestro left me an exception");
700 std::exception_ptr exception = std::move(self->exception);
701 self->exception = nullptr;
702 std::rethrow_exception(std::move(exception));
705 if (SMPI_switch_data_segment && not self->finished_) {
706 SMPI_switch_data_segment(self->iface());
710 /** @brief Returns the list of processes to run. */
711 const std::vector<smx_actor_t>& simgrid::simix::process_get_runnable()
713 return simix_global->process_to_run;
716 /** @brief Returns the process from PID. */
717 smx_actor_t SIMIX_process_from_PID(aid_t PID)
719 auto actor = simix_global->process_list.find(PID);
720 return actor == simix_global->process_list.end() ? nullptr : actor->second;
723 void SIMIX_process_on_exit(smx_actor_t actor, int_f_pvoid_pvoid_t fun, void* data)
725 SIMIX_process_on_exit(actor, [fun](int a, void* b) { fun((void*)(intptr_t)a, b); }, data);
728 void SIMIX_process_on_exit(smx_actor_t actor, std::function<void(int, void*)> fun, void* data)
730 xbt_assert(actor, "current process not found: are you in maestro context ?");
732 actor->on_exit.emplace_back(s_smx_process_exit_fun_t{fun, data});
735 /** @brief Restart a process, starting it again from the beginning. */
737 * @ingroup simix_process_management
738 * @brief Creates and runs a new SIMIX process.
740 * The structure and the corresponding thread are created and put in the list of ready processes.
742 * @param name a name for the process. It is for user-level information and can be nullptr.
743 * @param code the main function of the process
744 * @param data a pointer to any data one may want to attach to the new object. It is for user-level information and can
746 * It can be retrieved with the method ActorImpl::getUserData().
747 * @param host where the new agent is executed.
748 * @param properties the properties of the process
750 smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
751 std::unordered_map<std::string, std::string>* properties)
753 smx_actor_t self = SIMIX_process_self();
754 return simgrid::simix::simcall([name, code, data, host, properties, self] {
755 return simgrid::kernel::actor::ActorImpl::create(name, std::move(code), data, host, properties, self).get();
759 void simcall_process_set_data(smx_actor_t process, void* data)
761 simgrid::simix::simcall([process, data] { process->set_user_data(data); });