Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
3b42e4c5661830b6bec5f92d4153dc68ddeaaa31
[simgrid.git] / src / simix / ActorImpl.cpp
1 /* Copyright (c) 2007-2019. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include "mc/mc.h"
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_synchro_private.hpp"
20 #include "src/surf/HostImpl.hpp"
21 #include "src/surf/cpu_interface.hpp"
22
23 #include <boost/range/algorithm.hpp>
24
25 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_process, simix, "Logging specific to SIMIX (process)");
26
27 static unsigned long simix_process_maxpid = 0;
28
29 /**
30  * @brief Returns the current agent.
31  *
32  * This functions returns the currently running SIMIX process.
33  *
34  * @return The SIMIX process
35  */
36 smx_actor_t SIMIX_process_self()
37 {
38   smx_context_t self_context = simgrid::kernel::context::Context::self();
39
40   return (self_context != nullptr) ? self_context->get_actor() : nullptr;
41 }
42
43 /**
44  * @brief Returns whether a process has pending asynchronous communications.
45  * @return true if there are asynchronous communications in this process
46  */
47 int SIMIX_process_has_pending_comms(smx_actor_t process) {
48
49   return process->comms.size() > 0;
50 }
51
52 namespace simgrid {
53 namespace kernel {
54 namespace actor {
55
56 ActorImpl::ActorImpl(simgrid::xbt::string name, s4u::Host* host) : host_(host), name_(name), piface_(this)
57 {
58   pid_ = simix_process_maxpid++;
59   simcall.issuer = this;
60 }
61
62 ActorImpl::~ActorImpl()
63 {
64   delete this->context_;
65 }
66
67 void ActorImpl::cleanup()
68 {
69   if (this == simix_global->maestro_process) /* Do not cleanup maestro */
70     return;
71
72   XBT_DEBUG("Cleanup actor %s (%p), waiting synchro %p", get_cname(), this, waiting_synchro.get());
73
74   simix_global->mutex.lock();
75
76   simix_global->process_list.erase(pid_);
77   if (host_ && host_process_list_hook.is_linked())
78     simgrid::xbt::intrusive_erase(host_->pimpl_->process_list_, *this);
79   if (not smx_destroy_list_hook.is_linked()) {
80 #if SIMGRID_HAVE_MC
81     xbt_dynar_push_as(simix_global->dead_actors_vector, smx_actor_t, this);
82 #endif
83     simix_global->actors_to_destroy.push_back(*this);
84   }
85   context_->iwannadie = false;
86
87   simix_global->mutex.unlock();
88 }
89
90 void ActorImpl::exit()
91 {
92   context_->iwannadie = true;
93   blocked_            = false;
94   suspended_          = false;
95   exception_          = nullptr;
96
97   // Forcefully kill the actor if its host is turned off. Not a HostFailureException because you should not survive that
98   if (not host_->is_on())
99     this->throw_exception(std::make_exception_ptr(simgrid::kernel::context::StopRequest("host failed")));
100
101   /* destroy the blocking synchro if any */
102   if (waiting_synchro != nullptr) {
103
104     activity::ExecImplPtr exec   = boost::dynamic_pointer_cast<activity::ExecImpl>(waiting_synchro);
105     activity::CommImplPtr comm   = boost::dynamic_pointer_cast<activity::CommImpl>(waiting_synchro);
106     activity::SleepImplPtr sleep = boost::dynamic_pointer_cast<activity::SleepImpl>(waiting_synchro);
107     activity::RawImplPtr raw     = boost::dynamic_pointer_cast<activity::RawImpl>(waiting_synchro);
108     activity::IoImplPtr io       = boost::dynamic_pointer_cast<activity::IoImpl>(waiting_synchro);
109
110     if (exec != nullptr && exec->surf_action_) {
111       exec->cancel();
112       exec->surf_action_->unref();
113       exec->surf_action_ = nullptr;
114     } else if (comm != nullptr) {
115       comms.remove(waiting_synchro);
116       comm->cancel();
117       // Remove first occurrence of &actor->simcall:
118       auto i = boost::range::find(waiting_synchro->simcalls_, &simcall);
119       if (i != waiting_synchro->simcalls_.end())
120         waiting_synchro->simcalls_.remove(&simcall);
121     } else if (sleep != nullptr) {
122       if (sleep->surf_action_)
123         sleep->surf_action_->cancel();
124       sleep->post();
125     } else if (raw != nullptr) {
126       SIMIX_synchro_stop_waiting(this, &simcall);
127     } else if (io != nullptr) {
128       io->cancel();
129     } else {
130       simgrid::kernel::activity::ActivityImplPtr activity = waiting_synchro;
131       xbt_die("Activity %s is of unknown type %s", activity->get_cname(),
132               simgrid::xbt::demangle(typeid(activity).name()).get());
133     }
134
135     waiting_synchro = nullptr;
136   }
137 }
138
139 void ActorImpl::kill(ActorImpl* actor)
140 {
141   if (actor->finished_) {
142     XBT_DEBUG("Ignoring request to kill actor %s@%s that is already dead", actor->get_cname(),
143               actor->host_->get_cname());
144     return;
145   }
146
147   XBT_DEBUG("Actor '%s'@%s is killing actor '%s'@%s", get_cname(), host_->get_cname(), actor->get_cname(),
148             actor->host_->get_cname());
149
150   actor->exit();
151
152   if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) ==
153           end(simix_global->actors_to_run) &&
154       actor != this) {
155     XBT_DEBUG("Inserting %s in the to_run list", actor->get_cname());
156     simix_global->actors_to_run.push_back(actor);
157   }
158 }
159
160 void ActorImpl::kill_all()
161 {
162   for (auto const& kv : simix_global->process_list)
163     if (kv.second != this)
164       this->kill(kv.second);
165 }
166
167 void ActorImpl::set_kill_time(double kill_time)
168 {
169   if (kill_time <= SIMIX_get_clock())
170     return;
171   XBT_DEBUG("Set kill time %f for actor %s@%s", kill_time, get_cname(), host_->get_cname());
172   kill_timer = simix::Timer::set(kill_time, [this] {
173     this->exit();
174     kill_timer = nullptr;
175   });
176 }
177
178 double ActorImpl::get_kill_time()
179 {
180   return kill_timer ? kill_timer->get_date() : 0;
181 }
182
183 static void dying_daemon(int /*exit_status*/, void* data)
184 {
185   std::vector<ActorImpl*>* vect = &simix_global->daemons;
186
187   auto it = std::find(vect->begin(), vect->end(), static_cast<ActorImpl*>(data));
188   xbt_assert(it != vect->end(), "The dying daemon is not a daemon after all. Please report that bug.");
189
190   /* Don't move the whole content since we don't really care about the order */
191   std::swap(*it, vect->back());
192   vect->pop_back();
193 }
194
195 void ActorImpl::yield()
196 {
197   XBT_DEBUG("Yield actor '%s'", get_cname());
198
199   /* Go into sleep and return control to maestro */
200   context_->suspend();
201
202   /* Ok, maestro returned control to us */
203   XBT_DEBUG("Control returned to me: '%s'", get_cname());
204
205   if (context_->iwannadie) {
206
207     XBT_DEBUG("Actor %s@%s is dead", get_cname(), host_->get_cname());
208     // throw simgrid::kernel::context::StopRequest(); Does not seem to properly kill the actor
209     context_->stop();
210     THROW_IMPOSSIBLE;
211   }
212
213   if (suspended_) {
214     XBT_DEBUG("Hey! I'm suspended.");
215     xbt_assert(exception_ != nullptr, "Gasp! This exception may be lost by subsequent calls.");
216     suspended_ = false;
217     suspend(this);
218   }
219
220   if (exception_ != nullptr) {
221     XBT_DEBUG("Wait, maestro left me an exception");
222     std::exception_ptr exception = std::move(exception_);
223     exception_                   = nullptr;
224     std::rethrow_exception(std::move(exception));
225   }
226
227   if (SMPI_switch_data_segment && not finished_) {
228     SMPI_switch_data_segment(iface());
229   }
230 }
231
232 /** This actor will be terminated automatically when the last non-daemon actor finishes */
233 void ActorImpl::daemonize()
234 {
235   if (not daemon_) {
236     daemon_ = true;
237     simix_global->daemons.push_back(this);
238     SIMIX_process_on_exit(this, dying_daemon, this);
239   }
240 }
241
242 s4u::Actor* ActorImpl::restart()
243 {
244   XBT_DEBUG("Restarting actor %s on %s", get_cname(), host_->get_cname());
245
246   // retrieve the arguments of the old actor
247   ProcessArg arg = ProcessArg(host_, this);
248
249   // kill the old actor
250   (this == simix_global->maestro_process) ? this->exit() : SIMIX_process_self()->kill(this);
251
252   // start the new actor
253   ActorImplPtr actor =
254       ActorImpl::create(arg.name, std::move(arg.code), arg.data, arg.host, arg.properties.get(), nullptr);
255   actor->set_kill_time(arg.kill_time);
256   actor->set_auto_restart(arg.auto_restart);
257
258   return actor->ciface();
259 }
260
261 activity::ActivityImplPtr ActorImpl::suspend(ActorImpl* issuer)
262 {
263   if (suspended_) {
264     XBT_DEBUG("Actor '%s' is already suspended", get_cname());
265     return nullptr;
266   }
267
268   suspended_ = true;
269
270   /* If we are suspending another actor that is waiting on a sync, suspend its synchronization. */
271   if (this != issuer) {
272     if (waiting_synchro)
273       waiting_synchro->suspend();
274     /* If the other actor is not waiting, its suspension is delayed to when the actor is rescheduled. */
275
276     return nullptr;
277   } else {
278     return activity::ExecImplPtr(new activity::ExecImpl("suspend", "", nullptr, this->host_))->start(0.0, 1.0, 0.0);
279   }
280 }
281
282 void ActorImpl::resume()
283 {
284   XBT_IN("actor = %p", this);
285
286   if (context_->iwannadie) {
287     XBT_VERB("Ignoring request to suspend an actor that is currently dying.");
288     return;
289   }
290
291   if (not suspended_)
292     return;
293   suspended_ = false;
294
295   /* resume the synchronization that was blocking the resumed actor. */
296   if (waiting_synchro)
297     waiting_synchro->resume();
298
299   XBT_OUT();
300 }
301
302 activity::ActivityImplPtr ActorImpl::join(smx_actor_t actor, double timeout)
303 {
304   activity::ActivityImplPtr res = this->sleep(timeout);
305   intrusive_ptr_add_ref(res.get());
306   SIMIX_process_on_exit(actor,
307                         [](int, void* arg) {
308                           auto sleep = static_cast<simgrid::kernel::activity::SleepImpl*>(arg);
309                           if (sleep->surf_action_)
310                             sleep->surf_action_->finish(simgrid::kernel::resource::Action::State::FINISHED);
311                           intrusive_ptr_release(sleep);
312                         },
313                         res.get());
314   return res;
315 }
316
317 activity::ActivityImplPtr ActorImpl::sleep(double duration)
318 {
319   if (not host_->is_on())
320     throw_exception(std::make_exception_ptr(simgrid::HostFailureException(
321         XBT_THROW_POINT, std::string("Host ") + host_->get_cname() + " failed, you cannot sleep there.")));
322
323   return simgrid::kernel::activity::SleepImplPtr(new simgrid::kernel::activity::SleepImpl("sleep", host_))
324       ->start(duration);
325 }
326
327 void ActorImpl::throw_exception(std::exception_ptr e)
328 {
329   exception_ = e;
330
331   if (suspended_)
332     resume();
333
334   /* cancel the blocking synchro if any */
335   if (waiting_synchro) {
336
337     activity::ExecImplPtr exec = boost::dynamic_pointer_cast<activity::ExecImpl>(waiting_synchro);
338     if (exec != nullptr)
339       exec->cancel();
340
341     activity::CommImplPtr comm = boost::dynamic_pointer_cast<activity::CommImpl>(waiting_synchro);
342     if (comm != nullptr) {
343       comms.remove(comm);
344       comm->cancel();
345     }
346
347     activity::SleepImplPtr sleep = boost::dynamic_pointer_cast<activity::SleepImpl>(waiting_synchro);
348     if (sleep != nullptr) {
349       SIMIX_process_sleep_destroy(waiting_synchro);
350       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), this) ==
351               end(simix_global->actors_to_run) &&
352           this != SIMIX_process_self()) {
353         XBT_DEBUG("Inserting [%p] %s in the to_run list", this, get_cname());
354         simix_global->actors_to_run.push_back(this);
355       }
356     }
357
358     activity::RawImplPtr raw = boost::dynamic_pointer_cast<activity::RawImpl>(waiting_synchro);
359     if (raw != nullptr) {
360       SIMIX_synchro_stop_waiting(this, &simcall);
361     }
362
363     activity::IoImplPtr io = boost::dynamic_pointer_cast<activity::IoImpl>(waiting_synchro);
364     if (io != nullptr) {
365       io->cancel();
366     }
367   }
368   waiting_synchro = nullptr;
369 }
370
371 void ActorImpl::set_host(s4u::Host* dest)
372 {
373   simgrid::xbt::intrusive_erase(host_->pimpl_->process_list_, *this);
374   host_ = dest;
375   dest->pimpl_->process_list_.push_back(*this);
376 }
377
378 ActorImplPtr ActorImpl::create(std::string name, simix::ActorCode code, void* data, s4u::Host* host,
379                                std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
380 {
381
382   XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
383
384   if (not host->is_on()) {
385     XBT_WARN("Cannot launch actor '%s' on failed host '%s'", name.c_str(), host->get_cname());
386     return nullptr;
387   }
388
389   ActorImpl* actor = new ActorImpl(simgrid::xbt::string(name), host);
390
391   xbt_assert(code && host != nullptr, "Invalid parameters");
392   /* actor data */
393   actor->set_user_data(data);
394   actor->code = code;
395
396   if (parent_actor != nullptr)
397     actor->set_ppid(parent_actor->get_pid());
398
399   XBT_VERB("Create context %s", actor->get_cname());
400   actor->context_ = simix_global->context_factory->create_context(std::move(code), actor);
401
402   /* Add properties */
403   if (properties != nullptr)
404     for (auto const& kv : *properties)
405       actor->set_property(kv.first, kv.second);
406
407   /* Add the actor to its host's actor list */
408   host->pimpl_->process_list_.push_back(*actor);
409
410   XBT_DEBUG("Start context '%s'", actor->get_cname());
411
412   /* Now insert it in the global actor list and in the actor to run list */
413   simix_global->process_list[actor->get_pid()] = actor;
414   XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname());
415   simix_global->actors_to_run.push_back(actor);
416   intrusive_ptr_add_ref(actor);
417
418   /* The on_creation() signal must be delayed until there, where the pid and everything is set */
419   s4u::Actor::on_creation(actor->iface());
420
421   return ActorImplPtr(actor);
422 }
423
424 void create_maestro(simix::ActorCode code)
425 {
426   /* Create maestro actor and initialize it */
427   ActorImpl* maestro = new ActorImpl(xbt::string(""), /*host*/ nullptr);
428
429   if (not code) {
430     maestro->context_ = simix_global->context_factory->create_context(simix::ActorCode(), maestro);
431   } else {
432     maestro->context_ = simix_global->context_factory->create_maestro(code, maestro);
433   }
434
435   maestro->simcall.issuer       = maestro;
436   simix_global->maestro_process = maestro;
437 }
438
439 } // namespace actor
440 } // namespace kernel
441 }
442
443 smx_actor_t SIMIX_process_attach(const char* name, void* data, const char* hostname,
444                                  std::unordered_map<std::string, std::string>* properties, smx_actor_t parent_process)
445 {
446   // This is mostly a copy/paste from SIMIX_process_new(),
447   // it'd be nice to share some code between those two functions.
448
449   sg_host_t host = sg_host_by_name(hostname);
450   XBT_DEBUG("Attach process %s on host '%s'", name, hostname);
451
452   if (not host->is_on()) {
453     XBT_WARN("Cannot launch process '%s' on failed host '%s'", name, hostname);
454     return nullptr;
455   }
456
457   smx_actor_t actor = new simgrid::kernel::actor::ActorImpl(simgrid::xbt::string(name), host);
458   /* Actor data */
459   actor->set_user_data(data);
460   actor->code = nullptr;
461
462   if (parent_process != nullptr)
463     actor->set_ppid(parent_process->get_pid());
464
465   XBT_VERB("Create context %s", actor->get_cname());
466   xbt_assert(simix_global != nullptr, "simix is not initialized, please call MSG_init first");
467   actor->context_ = simix_global->context_factory->attach(actor);
468
469   /* Add properties */
470   if (properties != nullptr)
471     for (auto const& kv : *properties)
472       actor->set_property(kv.first, kv.second);
473
474   /* Add the process to it's host process list */
475   host->pimpl_->process_list_.push_back(*actor);
476
477   /* Now insert it in the global process list and in the process to run list */
478   simix_global->process_list[actor->get_pid()] = actor;
479   XBT_DEBUG("Inserting [%p] %s(%s) in the to_run list", actor, actor->get_cname(), host->get_cname());
480   simix_global->actors_to_run.push_back(actor);
481   intrusive_ptr_add_ref(actor);
482
483   auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(actor->context_);
484   xbt_assert(nullptr != context, "Not a suitable context");
485   context->attach_start();
486
487   /* The on_creation() signal must be delayed until there, where the pid and everything is set */
488   simgrid::s4u::ActorPtr tmp = actor->iface(); // Passing this directly to on_creation will lead to crashes
489   simgrid::s4u::Actor::on_creation(tmp);
490
491   return actor;
492 }
493
494 void SIMIX_process_detach()
495 {
496   auto* context = dynamic_cast<simgrid::kernel::context::AttachContext*>(simgrid::kernel::context::Context::self());
497   if (context == nullptr)
498     xbt_die("Not a suitable context");
499
500   context->get_actor()->cleanup();
501   context->attach_stop();
502 }
503
504
505 /** @deprecated When this function gets removed, also remove the xbt_ex class, that is only there to help users to
506  * transition */
507 void SIMIX_process_throw(smx_actor_t actor, xbt_errcat_t cat, int value, const char* msg)
508 {
509   SMX_EXCEPTION(actor, cat, value, msg);
510
511   if (actor->is_suspended())
512     actor->resume();
513
514   /* cancel the blocking synchro if any */
515   if (actor->waiting_synchro) {
516
517     simgrid::kernel::activity::ExecImplPtr exec =
518         boost::dynamic_pointer_cast<simgrid::kernel::activity::ExecImpl>(actor->waiting_synchro);
519     if (exec != nullptr)
520       exec->cancel();
521
522     simgrid::kernel::activity::CommImplPtr comm =
523         boost::dynamic_pointer_cast<simgrid::kernel::activity::CommImpl>(actor->waiting_synchro);
524     if (comm != nullptr) {
525       actor->comms.remove(comm);
526       comm->cancel();
527     }
528
529     simgrid::kernel::activity::SleepImplPtr sleep =
530         boost::dynamic_pointer_cast<simgrid::kernel::activity::SleepImpl>(actor->waiting_synchro);
531     if (sleep != nullptr) {
532       SIMIX_process_sleep_destroy(actor->waiting_synchro);
533       if (std::find(begin(simix_global->actors_to_run), end(simix_global->actors_to_run), actor) ==
534               end(simix_global->actors_to_run) &&
535           actor != SIMIX_process_self()) {
536         XBT_DEBUG("Inserting [%p] %s in the to_run list", actor, actor->get_cname());
537         simix_global->actors_to_run.push_back(actor);
538       }
539     }
540
541     simgrid::kernel::activity::RawImplPtr raw =
542         boost::dynamic_pointer_cast<simgrid::kernel::activity::RawImpl>(actor->waiting_synchro);
543     if (raw != nullptr) {
544       SIMIX_synchro_stop_waiting(actor, &actor->simcall);
545     }
546
547     simgrid::kernel::activity::IoImplPtr io =
548         boost::dynamic_pointer_cast<simgrid::kernel::activity::IoImpl>(actor->waiting_synchro);
549     if (io != nullptr) {
550       io->cancel();
551     }
552   }
553   actor->waiting_synchro = nullptr;
554 }
555
556 void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_actor_t actor)
557 {
558   smx_activity_t sync_suspend = actor->suspend(simcall->issuer);
559
560   if (actor != simcall->issuer) {
561     SIMIX_simcall_answer(simcall);
562   } else {
563     sync_suspend->simcalls_.push_back(simcall);
564     actor->waiting_synchro = sync_suspend;
565     actor->waiting_synchro->suspend();
566   }
567   /* If we are suspending ourselves, then just do not finish the simcall now */
568 }
569
570 int SIMIX_process_get_maxpid() {
571   return simix_process_maxpid;
572 }
573
574 int SIMIX_process_count()
575 {
576   return simix_global->process_list.size();
577 }
578
579 void* SIMIX_process_self_get_data()
580 {
581   smx_actor_t self = SIMIX_process_self();
582
583   if (self == nullptr) {
584     return nullptr;
585   }
586   return self->get_user_data();
587 }
588
589 void SIMIX_process_self_set_data(void *data)
590 {
591   SIMIX_process_self()->set_user_data(data);
592 }
593
594
595 /* needs to be public and without simcall because it is called
596    by exceptions and logging events */
597 const char* SIMIX_process_self_get_name() {
598
599   smx_actor_t process = SIMIX_process_self();
600   if (process == nullptr || process == simix_global->maestro_process)
601     return "maestro";
602
603   return process->get_cname();
604 }
605
606 void simcall_HANDLER_process_join(smx_simcall_t simcall, smx_actor_t process, double timeout)
607 {
608   if (process->finished_) {
609     // The joined process is already finished, just wake up the issuer process right away
610     simcall_process_sleep__set__result(simcall, SIMIX_DONE);
611     SIMIX_simcall_answer(simcall);
612     return;
613   }
614   smx_activity_t sync = simcall->issuer->join(process, timeout);
615   sync->simcalls_.push_back(simcall);
616   simcall->issuer->waiting_synchro = sync;
617 }
618
619 void simcall_HANDLER_process_sleep(smx_simcall_t simcall, double duration)
620 {
621   if (MC_is_active() || MC_record_replay_is_active()) {
622     MC_process_clock_add(simcall->issuer, duration);
623     simcall_process_sleep__set__result(simcall, SIMIX_DONE);
624     SIMIX_simcall_answer(simcall);
625     return;
626   }
627   smx_activity_t sync = simcall->issuer->sleep(duration);
628   sync->simcalls_.push_back(simcall);
629   simcall->issuer->waiting_synchro = sync;
630 }
631
632 void SIMIX_process_sleep_destroy(smx_activity_t synchro)
633 {
634   XBT_DEBUG("Destroy sleep synchro %p", synchro.get());
635   simgrid::kernel::activity::SleepImplPtr sleep =
636       boost::static_pointer_cast<simgrid::kernel::activity::SleepImpl>(synchro);
637
638   if (sleep->surf_action_) {
639     sleep->surf_action_->unref();
640     sleep->surf_action_ = nullptr;
641   }
642 }
643
644 /**
645  * @brief Calling this function makes the process to yield.
646  *
647  * Only the current process can call this function, giving back the control to maestro.
648  *
649  * @param self the current process
650  */
651
652 /** @brief Returns the list of processes to run.
653  * @deprecated
654  */
655 const std::vector<smx_actor_t>& simgrid::simix::process_get_runnable()
656 {
657   return simix_global->actors_to_run;
658 }
659
660 /** @brief Returns the process from PID. */
661 smx_actor_t SIMIX_process_from_PID(aid_t PID)
662 {
663   auto actor = simix_global->process_list.find(PID);
664   return actor == simix_global->process_list.end() ? nullptr : actor->second;
665 }
666
667 void SIMIX_process_on_exit(smx_actor_t actor, int_f_pvoid_pvoid_t fun, void* data)
668 {
669   SIMIX_process_on_exit(actor, [fun](int a, void* b) { fun((void*)(intptr_t)a, b); }, data);
670 }
671
672 void SIMIX_process_on_exit(smx_actor_t actor, std::function<void(int, void*)> fun, void* data)
673 {
674   xbt_assert(actor, "current process not found: are you in maestro context ?");
675
676   actor->on_exit.emplace_back(s_smx_process_exit_fun_t{fun, data});
677 }
678
679 /** @brief Restart a process, starting it again from the beginning. */
680 /**
681  * @ingroup simix_process_management
682  * @brief Creates and runs a new SIMIX process.
683  *
684  * The structure and the corresponding thread are created and put in the list of ready processes.
685  *
686  * @param name a name for the process. It is for user-level information and can be nullptr.
687  * @param code the main function of the process
688  * @param data a pointer to any data one may want to attach to the new object. It is for user-level information and can
689  * be nullptr.
690  * It can be retrieved with the method ActorImpl::getUserData().
691  * @param host where the new agent is executed.
692  * @param properties the properties of the process
693  */
694 smx_actor_t simcall_process_create(std::string name, simgrid::simix::ActorCode code, void* data, sg_host_t host,
695                                    std::unordered_map<std::string, std::string>* properties)
696 {
697   smx_actor_t self = SIMIX_process_self();
698   return simgrid::simix::simcall([name, code, data, host, properties, self] {
699     return simgrid::kernel::actor::ActorImpl::create(std::move(name), std::move(code), data, host, properties, self)
700         .get();
701   });
702 }
703
704 void simcall_process_set_data(smx_actor_t process, void* data)
705 {
706   simgrid::simix::simcall([process, data] { process->set_user_data(data); });
707 }