From: Frederic Suter Date: Mon, 4 Dec 2017 21:07:00 +0000 (+0100) Subject: convert process-join to actor-join X-Git-Tag: v3.18~167 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/0cd4d8c91c2648bdcb5d1f095132c0930e9427b7?ds=sidebyside;hp=-c convert process-join to actor-join --- 0cd4d8c91c2648bdcb5d1f095132c0930e9427b7 diff --git a/examples/s4u/CMakeLists.txt b/examples/s4u/CMakeLists.txt index f91d36412d..602bdf28f8 100644 --- a/examples/s4u/CMakeLists.txt +++ b/examples/s4u/CMakeLists.txt @@ -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 index 0000000000..843594f518 --- /dev/null +++ b/examples/s4u/actor-join/s4u-actor-join.cpp @@ -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 index 0000000000..b03b3e2ec7 --- /dev/null +++ b/examples/s4u/actor-join/s4u-actor-join.tesh @@ -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 diff --git a/include/simgrid/s4u/Actor.hpp b/include/simgrid/s4u/Actor.hpp index d22640c269..c6384f45bd 100644 --- a/include/simgrid/s4u/Actor.hpp +++ b/include/simgrid/s4u/Actor.hpp @@ -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: diff --git a/src/s4u/s4u_actor.cpp b/src/s4u/s4u_actor.cpp index ddb8fac0cf..c68dda314c 100644 --- a/src/s4u/s4u_actor.cpp +++ b/src/s4u/s4u_actor.cpp @@ -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; }); }