Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add daemonize for s4u actors too
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 4 Jul 2017 13:40:03 +0000 (15:40 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 4 Jul 2017 13:40:03 +0000 (15:40 +0200)
examples/s4u/CMakeLists.txt
examples/s4u/actor-daemon/s4u_actor-daemon.cpp [new file with mode: 0644]
examples/s4u/actor-daemon/s4u_actor-daemon.tesh [new file with mode: 0644]
include/simgrid/s4u/Actor.hpp
src/msg/msg_process.cpp
src/s4u/s4u_actor.cpp

index 088ef9e..dfdc634 100644 (file)
@@ -1,4 +1,4 @@
-foreach (example actions-comm actions-storage actor-create actor-kill actor-migration actor-suspend 
+foreach (example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend 
                  app-masterworker app-token-ring io  mutex )
   add_executable       (s4u_${example}  ${example}/s4u_${example}.cpp)
   target_link_libraries(s4u_${example}  simgrid)
                  app-masterworker app-token-ring io  mutex )
   add_executable       (s4u_${example}  ${example}/s4u_${example}.cpp)
   target_link_libraries(s4u_${example}  simgrid)
@@ -31,7 +31,7 @@ set(txt_files     ${txt_files}    ${CMAKE_CURRENT_SOURCE_DIR}/actions-comm/s4u_a
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u_actions-storage.txt
                                   ${CMAKE_CURRENT_SOURCE_DIR}/README.doc                                   PARENT_SCOPE)
 
                                   ${CMAKE_CURRENT_SOURCE_DIR}/actions-storage/s4u_actions-storage.txt
                                   ${CMAKE_CURRENT_SOURCE_DIR}/README.doc                                   PARENT_SCOPE)
 
-foreach(example actions-comm actions-storage actor-create actor-kill actor-migration actor-suspend 
+foreach(example actions-comm actions-storage actor-create actor-daemon actor-kill actor-migration actor-suspend 
                  app-masterworker app-token-ring dht-chord io mutex )
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u_${example}.tesh)
 endforeach()
                  app-masterworker app-token-ring dht-chord io mutex )
   ADD_TESH_FACTORIES(s4u-${example} "thread;ucontext;raw;boost" --setenv bindir=${CMAKE_CURRENT_BINARY_DIR}/${example} --setenv srcdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --cd ${CMAKE_HOME_DIRECTORY}/examples/s4u/${example} s4u_${example}.tesh)
 endforeach()
diff --git a/examples/s4u/actor-daemon/s4u_actor-daemon.cpp b/examples/s4u/actor-daemon/s4u_actor-daemon.cpp
new file mode 100644 (file)
index 0000000..5ef84f6
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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_actor_daemon, "Messages specific for this s4u example");
+
+/* The worker process, working for a while before leaving */
+static void worker()
+{
+  XBT_INFO("Let's do some work (for 10 sec on Boivin).");
+  simgrid::s4u::this_actor::execute(980.95e6);
+
+  XBT_INFO("I'm done now. I leave even if it makes the daemon die.");
+}
+
+/* The daemon, displaying a message every 3 seconds until all other processes stop */
+static void my_daemon()
+{
+  simgrid::s4u::Actor::self()->daemonize();
+
+  while (1) {
+    XBT_INFO("Hello from the infinite loop");
+    simgrid::s4u::this_actor::sleep_for(3.0);
+  }
+
+  XBT_INFO("I will never reach that point: daemons are killed when regular processes are done");
+}
+
+int main(int argc, char* argv[])
+{
+  simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+
+  e->loadPlatform(argv[1]);
+  simgrid::s4u::Actor::createActor("worker", simgrid::s4u::Host::by_name("Boivin"), worker);
+  simgrid::s4u::Actor::createActor("daemon", simgrid::s4u::Host::by_name("Tremblay"), my_daemon);
+
+  e->run();
+
+  return 0;
+}
diff --git a/examples/s4u/actor-daemon/s4u_actor-daemon.tesh b/examples/s4u/actor-daemon/s4u_actor-daemon.tesh
new file mode 100644 (file)
index 0000000..bc42237
--- /dev/null
@@ -0,0 +1,11 @@
+#! ./tesh
+
+p Testing the process daemonization feature
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u_actor-daemon ${srcdir:=.}/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [  0.000000] (worker@Boivin) Let's do some work (for 10 sec on Boivin).
+> [  0.000000] (daemon@Tremblay) Hello from the infinite loop
+> [  3.000000] (daemon@Tremblay) Hello from the infinite loop
+> [  6.000000] (daemon@Tremblay) Hello from the infinite loop
+> [  9.000000] (daemon@Tremblay) Hello from the infinite loop
+> [ 10.000000] (worker@Boivin) I'm done now. I leave even if it makes the daemon die.
index d50ac13..f8febaa 100644 (file)
@@ -195,7 +195,7 @@ public:
 
   // ***** Methods *****
   /** This actor will be automatically terminated when the last non-daemon process finishes **/
 
   // ***** Methods *****
   /** This actor will be automatically terminated when the last non-daemon process finishes **/
-  void deamonize();
+  void daemonize();
 
   /** Retrieves the name of that actor as a C string */
   const char* cname();
 
   /** Retrieves the name of that actor as a C string */
   const char* cname();
index ffe758f..e8e8b2f 100644 (file)
@@ -479,9 +479,7 @@ XBT_PUBLIC(msg_process_t) MSG_process_restart(msg_process_t process) {
  */
 XBT_PUBLIC(void) MSG_process_daemonize(msg_process_t process)
 {
  */
 XBT_PUBLIC(void) MSG_process_daemonize(msg_process_t process)
 {
-  simgrid::simix::kernelImmediate([process]() {
-    process->getImpl()->daemonize();
-  });
+  simgrid::simix::kernelImmediate([process]() { process->getImpl()->daemonize(); });
 }
 
 /** @ingroup m_process_management
 }
 
 /** @ingroup m_process_management
index 3b27ed8..f9b2cf9 100644 (file)
@@ -80,6 +80,11 @@ s4u::Host* Actor::host()
   return this->pimpl_->host;
 }
 
   return this->pimpl_->host;
 }
 
+void Actor::daemonize()
+{
+  simgrid::simix::kernelImmediate([this]() { pimpl_->daemonize(); });
+}
+
 const char* Actor::cname()
 {
   return this->pimpl_->name.c_str();
 const char* Actor::cname()
 {
   return this->pimpl_->name.c_str();