Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert process-join to actor-join
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 4 Dec 2017 21:07:00 +0000 (22:07 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 4 Dec 2017 21:07:00 +0000 (22:07 +0100)
examples/s4u/CMakeLists.txt
examples/s4u/actor-join/s4u-actor-join.cpp [new file with mode: 0644]
examples/s4u/actor-join/s4u-actor-join.tesh [new file with mode: 0644]
include/simgrid/s4u/Actor.hpp
src/s4u/s4u_actor.cpp

index f91d364..602bdf2 100644 (file)
@@ -1,5 +1,5 @@
 foreach (example actions-comm actions-storage 
-                 actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
+                 actor-create actor-daemon actor-execute actor-join actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
                  app-masterworker app-pingpong app-token-ring
                  async-wait async-waitany async-waitall
                  energy-link energy-pstate energy-ptask
@@ -67,7 +67,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u-a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/README.doc                                   PARENT_SCOPE)
 
 foreach(example actions-comm actions-storage 
-                actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
+                actor-create actor-daemon actor-execute actor-join actor-kill actor-lifetime actor-migration actor-suspend actor-priority actor-yield
                 app-bittorrent app-masterworker app-pingpong app-token-ring 
                 async-wait async-waitall async-waitany
                 dht-chord 
diff --git a/examples/s4u/actor-join/s4u-actor-join.cpp b/examples/s4u/actor-join/s4u-actor-join.cpp
new file mode 100644 (file)
index 0000000..843594f
--- /dev/null
@@ -0,0 +1,65 @@
+/* Copyright (c) 2017. 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. */
+
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example");
+
+static void sleeper()
+{
+  XBT_INFO("Sleeper started");
+  simgrid::s4u::this_actor::sleep_for(3);
+  XBT_INFO("I'm done. See you!");
+}
+
+static void master()
+{
+  simgrid::s4u::ActorPtr actor;
+
+  XBT_INFO("Start sleeper");
+  actor = simgrid::s4u::Actor::createActor("sleeper from master", simgrid::s4u::Host::current(), sleeper);
+  XBT_INFO("Join the sleeper (timeout 2)");
+  actor->join(2);
+
+  XBT_INFO("Start sleeper");
+  actor = simgrid::s4u::Actor::createActor("sleeper from master", simgrid::s4u::Host::current(), sleeper);
+  XBT_INFO("Join the sleeper (timeout 4)");
+  actor->join(4);
+
+  XBT_INFO("Start sleeper");
+  actor = simgrid::s4u::Actor::createActor("sleeper from master", simgrid::s4u::Host::current(), sleeper);
+  XBT_INFO("Join the sleeper (timeout 2)");
+  actor->join(2);
+
+  XBT_INFO("Start sleeper");
+  actor = simgrid::s4u::Actor::createActor("sleeper from master", simgrid::s4u::Host::current(), sleeper);
+  XBT_INFO("Waiting 4");
+  simgrid::s4u::this_actor::sleep_for(4);
+  XBT_INFO("Join the sleeper after its end (timeout 1)");
+  actor->join(1);
+
+  XBT_INFO("Goodbye now!");
+
+  simgrid::s4u::this_actor::sleep_for(1);
+
+  XBT_INFO("Goodbye now!");
+}
+
+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]);
+
+  e.loadPlatform(argv[1]);
+
+  simgrid::s4u::Actor::createActor("master", simgrid::s4u::Host::by_name("Tremblay"), master);
+
+  e.run();
+
+  XBT_INFO("Simulation time %g", simgrid::s4u::Engine::getClock());
+
+  return 0;
+}
diff --git a/examples/s4u/actor-join/s4u-actor-join.tesh b/examples/s4u/actor-join/s4u-actor-join.tesh
new file mode 100644 (file)
index 0000000..b03b3e2
--- /dev/null
@@ -0,0 +1,21 @@
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-join$EXEEXT ${platfdir}/small_platform.xml
+> [Tremblay:master:(1) 0.000000] [s4u_test/INFO] Start sleeper
+> [Tremblay:sleeper from master:(2) 0.000000] [s4u_test/INFO] Sleeper started
+> [Tremblay:master:(1) 0.000000] [s4u_test/INFO] Join the sleeper (timeout 2)
+> [Tremblay:master:(1) 2.000000] [s4u_test/INFO] Start sleeper
+> [Tremblay:sleeper from master:(3) 2.000000] [s4u_test/INFO] Sleeper started
+> [Tremblay:master:(1) 2.000000] [s4u_test/INFO] Join the sleeper (timeout 4)
+> [Tremblay:sleeper from master:(2) 3.000000] [s4u_test/INFO] I'm done. See you!
+> [Tremblay:sleeper from master:(3) 5.000000] [s4u_test/INFO] I'm done. See you!
+> [Tremblay:master:(1) 5.000000] [s4u_test/INFO] Start sleeper
+> [Tremblay:sleeper from master:(4) 5.000000] [s4u_test/INFO] Sleeper started
+> [Tremblay:master:(1) 5.000000] [s4u_test/INFO] Join the sleeper (timeout 2)
+> [Tremblay:master:(1) 7.000000] [s4u_test/INFO] Start sleeper
+> [Tremblay:sleeper from master:(5) 7.000000] [s4u_test/INFO] Sleeper started
+> [Tremblay:master:(1) 7.000000] [s4u_test/INFO] Waiting 4
+> [Tremblay:sleeper from master:(4) 8.000000] [s4u_test/INFO] I'm done. See you!
+> [Tremblay:sleeper from master:(5) 10.000000] [s4u_test/INFO] I'm done. See you!
+> [Tremblay:master:(1) 11.000000] [s4u_test/INFO] Join the sleeper after its end (timeout 1)
+> [Tremblay:master:(1) 11.000000] [s4u_test/INFO] Goodbye now!
+> [Tremblay:master:(1) 12.000000] [s4u_test/INFO] Goodbye now!
+> [12.000000] [s4u_test/INFO] Simulation time 12
index d22640c..c6384f4 100644 (file)
@@ -258,6 +258,7 @@ public:
    * This blocks the calling actor until the actor on which we call join() is terminated
    */
   void join();
+  void join(double timeout);
 
   // Static methods on all actors:
 
index ddb8fac..c68dda3 100644 (file)
@@ -61,6 +61,11 @@ void Actor::join() {
   simcall_process_join(this->pimpl_, -1);
 }
 
+void Actor::join(double timeout)
+{
+  simcall_process_join(this->pimpl_, timeout);
+}
+
 void Actor::setAutoRestart(bool autorestart) {
   simgrid::simix::kernelImmediate([this, autorestart]() { pimpl_->auto_restart = autorestart; });
 }