Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Spell check.
[simgrid.git] / examples / s4u / actor-exiting / s4u-actor-exiting.cpp
index d24aab7..cc7e9f6 100644 (file)
@@ -5,7 +5,7 @@
 
 /* There is two very different ways of being informed when an actor exits.
  *
- * The this_actor::on_exit() function allows to register a function to be
+ * The this_actor::on_exit() function allows one to register a function to be
  * executed when this very actor exits. The registered function will run
  * when this actor terminates (either because its main function returns, or
  * because it's killed in any way). No simcall are allowed here: your actor
  * 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.
+ * when developing 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.
@@ -45,13 +51,16 @@ static void actor_b()
 int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
-  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s msg_platform.xml\n", argv[0], argv[0]);
+  xbt_assert(argc == 2, "Usage: %s platform_file\n\tExample: %s ../platforms/small_platform.xml\n", argv[0], argv[0]);
 
   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::ActorPtr 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);