-foreach(example actor-create actor-migration actor-yield exec-basic)
+foreach(example actor-create actor-join actor-migration actor-yield
+ exec-basic)
set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.tesh)
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${example}/${example}.py)
--- /dev/null
+# Copyright (c) 2017-2018. The SimGrid Team. All rights reserved.
+#
+# This program is free software you can redistribute it and/or modify it
+# under the terms of the license (GNU LGPL) which comes with this package.
+
+from simgrid import *
+import sys
+
+def sleeper():
+ this_actor.info("Sleeper started")
+ this_actor.sleep_for(3)
+ this_actor.info("I'm done. See you!")
+
+def master():
+ this_actor.info("Start sleeper")
+ actor = Actor.create("sleeper from master", Host.current(), sleeper)
+ this_actor.info("Join the sleeper (timeout 2)")
+ actor.join(2)
+
+ this_actor.info("Start sleeper")
+ actor = Actor.create("sleeper from master", Host.current(), sleeper)
+ this_actor.info("Join the sleeper (timeout 4)")
+ actor.join(4)
+
+ this_actor.info("Start sleeper")
+ actor = Actor.create("sleeper from master", Host.current(), sleeper)
+ this_actor.info("Join the sleeper (timeout 2)")
+ actor.join(2)
+
+ this_actor.info("Start sleeper")
+ actor = Actor.create("sleeper from master", Host.current(), sleeper)
+ this_actor.info("Waiting 4")
+ this_actor.sleep_for(4)
+ this_actor.info("Join the sleeper after its end (timeout 1)")
+ actor.join(1)
+
+ this_actor.info("Goodbye now!")
+
+ this_actor.sleep_for(1)
+
+ this_actor.info("Goodbye now!")
+
+if __name__ == '__main__':
+ e = Engine(sys.argv)
+ if len(sys.argv) < 2: raise AssertionError("Usage: actor-join.py platform_file [other parameters]")
+
+ e.load_platform(sys.argv[1])
+
+ Actor.create("master", Host.by_name("Tremblay"), master)
+
+ e.run()
+
+ this_actor.info("Simulation time {}".format(Engine.get_clock()))
--- /dev/null
+$ python3 ${bindir:=.}/actor-join.py ${platfdir}/small_platform.xml
+> [Tremblay:master:(1) 0.000000] [python/INFO] Start sleeper
+> [Tremblay:sleeper from master:(2) 0.000000] [python/INFO] Sleeper started
+> [Tremblay:master:(1) 0.000000] [python/INFO] Join the sleeper (timeout 2)
+> [Tremblay:master:(1) 2.000000] [python/INFO] Start sleeper
+> [Tremblay:sleeper from master:(3) 2.000000] [python/INFO] Sleeper started
+> [Tremblay:master:(1) 2.000000] [python/INFO] Join the sleeper (timeout 4)
+> [Tremblay:sleeper from master:(2) 3.000000] [python/INFO] I'm done. See you!
+> [Tremblay:sleeper from master:(3) 5.000000] [python/INFO] I'm done. See you!
+> [Tremblay:master:(1) 5.000000] [python/INFO] Start sleeper
+> [Tremblay:sleeper from master:(4) 5.000000] [python/INFO] Sleeper started
+> [Tremblay:master:(1) 5.000000] [python/INFO] Join the sleeper (timeout 2)
+> [Tremblay:master:(1) 7.000000] [python/INFO] Start sleeper
+> [Tremblay:sleeper from master:(5) 7.000000] [python/INFO] Sleeper started
+> [Tremblay:master:(1) 7.000000] [python/INFO] Waiting 4
+> [Tremblay:sleeper from master:(4) 8.000000] [python/INFO] I'm done. See you!
+> [Tremblay:sleeper from master:(5) 10.000000] [python/INFO] I'm done. See you!
+> [Tremblay:master:(1) 11.000000] [python/INFO] Join the sleeper after its end (timeout 1)
+> [Tremblay:master:(1) 11.000000] [python/INFO] Goodbye now!
+> [Tremblay:master:(1) 12.000000] [python/INFO] Goodbye now!
+> [12.000000] [python/INFO] Simulation time 12.0
:py:func:`simgrid.this_actor.migrate()` |py|
- **Waiting for the termination of an actor:** (joining on it)
- :cpp:func:`simgrid::s4u::Actor::join()` allows to block the current
- actor until the end of the receiving actor.
- |br| `examples/s4u/actor-join/s4u-actor-join.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-join/s4u-actor-join.cpp>`_
+ You can block the current actor until the end of another actor.
+ |br| |cpp| `examples/s4u/actor-join/s4u-actor-join.cpp <https://framagit.org/simgrid/simgrid/tree/master/examples/s4u/actor-join/s4u-actor-join.cpp>`_
+ :cpp:func:`simgrid::s4u::Actor::join()` |cpp|
+ |br| |py| `examples/python/actor-join/actor-join.py <https://framagit.org/simgrid/simgrid/tree/master/examples/python/actor-join/actor-join.py>`_
+ :cpp:func:`simgrid.Actor.join()` |py|
- **Yielding to other actors**.
The ```yield()``` function interrupts the execution of the current
/** Wait for the actor to finish.
*
- * This blocks the calling actor until the actor on which we call join() is terminated
+ * Blocks the calling actor until the joined actor is terminated. If actor alice executes bob.join(), then alice is
+ * blocked until bob terminates.
*/
void join();
+
+ /** Wait for the actor to finish, or for the timeout to elapse.
+ *
+ * Blocks the calling actor until the joined actor is terminated. If actor alice executes bob.join(), then alice is
+ * blocked until bob terminates.
+ */
void join(double timeout);
Actor* restart();
static Host* by_name_or_null(std::string name);
/** Retrieve a host from its name, or die */
static s4u::Host* by_name(std::string name);
- /** Retrieve the host on which the current actor is running */
+ /** Retrieves the host on which the running actor is located */
static s4u::Host* current();
/** Retrieves the name of that host as a C++ string */
// Currently this can be dangling, we should wrap this somehow.
return new simgrid::s4u::Engine(&argc, argv.get());
}))
+ .def("get_clock", &Engine::get_clock, "Retrieve the simulation time")
.def("load_platform", &Engine::load_platform,
"Load a platform file describing the environment, see :cpp:func:`simgrid::s4u::Engine::load_platform()`")
.def("load_deployment", &Engine::load_deployment,
/* Class Host */
py::class_<simgrid::s4u::Host, std::unique_ptr<Host, py::nodelete>>(m, "Host", "Simulation Engine, see :ref:`class s4u::Host <API_s4u_Host>`")
- .def("by_name", &Host::by_name, "Retrieve a host from its name, or die")
+ .def("by_name", &Host::by_name, "Retrieves a host from its name, or die")
+ .def("current", &Host::current, "Retrieves the host on which the running actor is located, see :cpp:func:`simgrid::s4u::Host::current()`")
.def_property_readonly("name", [](Host* self) -> const std::string {
return static_cast<std::string>(self->get_name());
}, "Retrieve the name of this host")
},
"Create an actor from a function or an object, see :cpp:func:`simgrid::s4u::Actor::create()`")
.def_property("host", &Actor::get_host, &Actor::migrate, "The host on which this actor is located")
+ .def("join", py::overload_cast<double>(&Actor::join), "Wait for the actor to finish, see :cpp:func:`void simgrid::s4u::Actor::join(double)`",
+ py::arg("timeout"))
.def("migrate", &Actor::migrate, "Moves that actor to another host, see :cpp:func:`void simgrid::s4u::Actor::migrate()`",
- py::arg("dest"))
+ py::arg("dest"))
.def("suspend", &Actor::suspend, "Suspend that actor, that is blocked until resume()ed by another actor. See :cpp:func:`void simgrid::s4u::Actor::suspend()`")
.def("resume", &Actor::resume, "Resume that actor, that was previously suspend()ed. See :cpp:func:`void simgrid::s4u::Actor::suspend()`");