- Barrier::wait returns SG_BARRIER_SERIAL_THREAD for (only) one actor
for consistency with pthread_barrier_wait()
- Host::get_englobing_zone() returns the englobing netzone
+ - Actor::on_destruction is now called in the destructor
+ Actor::on_termination new signal called when the actor terminates
+ its code.
MSG:
- convert a new set of functions to the S4U C interface and move the old MSG
of doing so, depending of whether you want your callback to be
executed when a specific actor ends (with ```this_actor::on_exit()```)
or whether it should be executed when any actor ends (with
+ ```Actor::on_termination()```) or when it gets destroyed (with
```Actor::on_destruction()```)
- |cpp| `examples/s4u/actor-exiting/s4u-actor-exiting.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-exiting/s4u-actor-exiting.cpp>`_
* Usually, the functions registered in this_actor::on_exit() are in charge
* of releasing any memory allocated by the actor during its execution.
*
- * The other way of getting informed when an actor dies is to connect a
- * function in the Actor::on_destruction signal, that is shared between
+ * The other way of getting informed when an actor terminates is to connect a
+ * function in the Actor::on_termination signal, that is shared between
* all actors. Callbacks to this signal are executed for each terminating
* actors, no matter what. This is useful in many cases, in particular
* when developping SimGrid plugins.
*
+ * Finally, you can attach callbacks to the Actor::on_destruction signal.
+ * It is also shared between all actors, and gets fired when the actors
+ * are destroyed. A delay is possible between the termination of an actor
+ * (ie, when it terminates executing its code) and its destruction (ie,
+ * when it is not referenced anywhere in the simulation and can be collected).
+ *
* In both cases, you can stack more than one callback in the signal.
* They will all be executed in the registration order.
*/
e.load_platform(argv[1]); /* - Load the platform description */
- /* Register a callback in the Actor::on_destruction signal. It will be called for every terminated actors */
+ /* Register a callback in the Actor::on_termination signal. It will be called for every terminated actors */
+ simgrid::s4u::Actor::on_termination.connect(
+ [](simgrid::s4u::Actor const& actor) { XBT_INFO("Actor %s terminates now", actor.get_cname()); });
+ /* Register a callback in the Actor::on_destruction signal. It will be called for every destructed actors */
simgrid::s4u::Actor::on_destruction.connect(
- [](simgrid::s4u::Actor const& actor) { XBT_INFO("Actor %s stops now", actor.get_cname()); });
+ [](simgrid::s4u::Actor const& actor) { XBT_INFO("Actor %s gets destroyed now", actor.get_cname()); });
/* Create some actors */
simgrid::s4u::Actor::create("A", simgrid::s4u::Host::by_name("Tremblay"), actor_a);
$ ${bindir:=.}/s4u-actor-exiting ${platfdir}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
> [ 10.194200] (A@Tremblay) I stop now
-> [ 10.194200] (maestro@) Actor A stops now
-> [ 26.213694] (maestro@) Actor B stops now
+> [ 10.194200] (maestro@) Actor A terminates now
+> [ 26.213694] (maestro@) Actor A gets destroyed now
+> [ 26.213694] (maestro@) Actor B terminates now
+> [ 26.213694] (maestro@) Actor B gets destroyed now
> 13 11.904056 2 1
> 12 11.904056 2 1 18
> 13 11.904056 2 1
-> 7 11.904056 1 1
> 13 11.905518 2 2
> 13 11.905518 2 2
> 12 11.905518 2 2 18
-> 7 11.905518 1 2
> 13 11.906032 2 3
> 12 11.906032 2 3 18
> 13 11.906032 2 3
+> 7 11.906032 1 1
+> 7 11.906032 1 2
> 7 11.906032 1 3
$ rm -f ${bindir:=.}/smpi_trace.trace
static xbt::signal<void(Actor const&)> on_migration_start;
/** Signal to others that an actor is has been migrated to another host **/
static xbt::signal<void(Actor const&)> on_migration_end;
- /** Signal indicating that an actor is about to disappear.
- * This signal is fired for any dying actor, which is mostly useful when designing plugins and extensions. If you
- * want to register to the termination of a given actor, use this_actor::on_exit() instead.*/
+ /** Signal indicating that an actor terminated its code.
+ * The actor may continue to exist if it is still referenced in the simulation, but it's not active anymore.
+ * If you want to free extra data when the actor's destructor is called, use Actor::on_destruction.
+ * If you want to register to the termination of a given actor, use this_actor::on_exit() instead.*/
+ static xbt::signal<void(Actor const&)> on_termination;
+ /** Signal indicating that an actor is about to disappear (its destructor was called).
+ * This signal is fired for any destructed actor, which is mostly useful when designing plugins and extensions.
+ * If you want to react to the end of the actor's code, use Actor::on_termination instead.
+ * If you want to register to the termination of a given actor, use this_actor::on_exit() instead.*/
static xbt::signal<void(Actor const&)> on_destruction;
/** Create an actor from a std::function<void()>
ActorImpl::~ActorImpl()
{
- context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
- simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_destruction(*ciface()); });
- context_->iwannadie = true;
+ if (this != simix_global->maestro_process) {
+ context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+ simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_destruction(*ciface()); });
+ context_->iwannadie = true;
+ }
}
/* Become an actor in the simulation
}
simix_global->mutex.unlock();
+
+ context_->iwannadie = false; // don't let the simcall's yield() do a Context::stop(), to avoid infinite loops
+ simgrid::simix::simcall([this] { simgrid::s4u::Actor::on_termination(*ciface()); });
+ context_->iwannadie = true;
}
void ActorImpl::exit()
xbt::signal<void(Actor const&)> s4u::Actor::on_wake_up;
xbt::signal<void(Actor const&)> s4u::Actor::on_migration_start;
xbt::signal<void(Actor const&)> s4u::Actor::on_migration_end;
+xbt::signal<void(Actor const&)> s4u::Actor::on_termination;
xbt::signal<void(Actor const&)> s4u::Actor::on_destruction;
// ***** Actor creation *****