-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)
${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()
--- /dev/null
+/* 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;
+}
--- /dev/null
+#! ./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.
// ***** 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();
*/
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
return this->pimpl_->host;
}
+void Actor::daemonize()
+{
+ simgrid::simix::kernelImmediate([this]() { pimpl_->daemonize(); });
+}
+
const char* Actor::cname()
{
return this->pimpl_->name.c_str();