/** If set to true, the actor will automatically restart when its host reboots */
void setAutoRestart(bool autorestart);
+
+ /** Add a function to the list of "on_exit" functions for the current actor. The on_exit functions are the functions
+ * executed when your actor is killed. You should use them to free the data used by your process.
+ */
+ void onExit(int_f_pvoid_pvoid_t fun, void* data);
+
/** Sets the time at which that actor should be killed */
void setKillTime(double time);
/** Retrieves the time at which that actor will be killed (or -1 if not set) */
/** Ask kindly to all actors to die. Only the issuer will survive. */
static void killAll();
+ static void killAll(int resetPid);
/** Returns the internal implementation of this actor */
simix::ActorImpl* getImpl();
/** @brief kill the actor. */
XBT_PUBLIC(void) kill();
+ /** @brief Add a function to the list of "on_exit" functions. */
+ XBT_PUBLIC(void) onExit(int_f_pvoid_pvoid_t fun, void* data);
+
/** @brief Migrate the actor to a new host. */
XBT_PUBLIC(void) migrate(Host* new_host);
};
simcall_process_auto_restart_set(pimpl_,autorestart);
}
+void Actor::onExit(int_f_pvoid_pvoid_t fun, void* data)
+{
+ simcall_process_on_exit(pimpl_, fun, data);
+}
+
void Actor::migrate(Host* new_host)
{
simcall_process_set_host(pimpl_, new_host);
return ActorPtr();
}
-void Actor::killAll() {
+void Actor::killAll()
+{
simcall_process_killall(1);
}
+void Actor::killAll(int resetPid)
+{
+ simcall_process_killall(resetPid);
+}
+
// ***** this_actor *****
namespace this_actor {
simcall_process_kill(SIMIX_process_self());
}
+void onExit(int_f_pvoid_pvoid_t fun, void* data)
+{
+ simcall_process_on_exit(SIMIX_process_self(), fun, data);
+}
+
void migrate(Host* new_host)
{
simcall_process_set_host(SIMIX_process_self(), new_host);
# C examples
-foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async pid
+foreach(x concurrent_rw get_sender host_on_off host_on_off_recv host_on_off_processes host_on_off_wait listen_async
storage_client_server trace_integration)
add_executable (${x} ${x}/${x}.c)
target_link_libraries(${x} simgrid)
${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp1-c1s1-c3s2.xml
${CMAKE_CURRENT_SOURCE_DIR}/trace_integration/test-hbp2.5-hbp1.5.xml PARENT_SCOPE)
-foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async pid
+foreach(x concurrent_rw get_sender host_on_off host_on_off_processes host_on_off_recv host_on_off_wait listen_async
process storage_client_server task_destroy_cancel trace_integration)
ADD_TESH_FACTORIES(tesh-msg-${x} "thread;boost;ucontext;raw" --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x} --cd ${CMAKE_BINARY_DIR}/teshsuite/msg/${x} ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/${x}/${x}.tesh)
endforeach()
+++ /dev/null
-/* Copyright (c) 2009-2010, 2013-2015. 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/msg.h"
-
-XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
-
-const char* mailbox = "mailbox";
-#define task_comp_size 1000
-#define task_comm_size 100000
-
-static int my_onexit(smx_process_exit_status_t status, int *pid){
- XBT_INFO("Process \"%d\" killed.", *pid);
- return 0;
-}
-
-static int sendpid(int argc, char *argv[])
-{
- int pid = MSG_process_self_PID();
- MSG_process_on_exit((int_f_pvoid_pvoid_t)my_onexit, &pid);
- msg_task_t task = MSG_task_create("pid", task_comp_size, task_comm_size, &pid);
- XBT_INFO("Sending pid of \"%d\".", pid);
- MSG_task_send(task, mailbox);
- XBT_INFO("Send of pid \"%d\" done.", pid);
- MSG_process_suspend(MSG_process_self());
- return 0;
-}
-
-static int killall(int argc, char *argv[]){
- msg_task_t task = NULL;
-
- for (int i=0; i<3;i++) {
- MSG_task_receive(&(task), mailbox);
- int pid = *(int*)MSG_task_get_data(task);
- MSG_task_destroy(task);
- XBT_INFO("Killing process \"%d\".", pid);
- MSG_process_kill(MSG_process_from_PID(pid));
- task = NULL;
- }
- return 0;
-}
-
-int main(int argc, char* argv[])
-{
- MSG_init(&argc, argv);
-
- xbt_assert(argc >= 2, "Usage: pid platform pid_to_kill");
-
- MSG_process_killall(atoi(argv[2]));
-
- MSG_create_environment(argv[1]);
- MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
- MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
- MSG_process_create("sendpid", sendpid, NULL, MSG_get_host_by_name("Tremblay"));
- MSG_process_create("killall", killall, NULL, MSG_get_host_by_name("Tremblay"));
-
- return MSG_main() != MSG_OK;
-}
+++ /dev/null
-$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 0 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [ 0.000000] (1:sendpid@Tremblay) Sending pid of "1".
-> [ 0.000000] (2:sendpid@Tremblay) Sending pid of "2".
-> [ 0.000000] (3:sendpid@Tremblay) Sending pid of "3".
-> [ 0.000402] (4:killall@Tremblay) Killing process "1".
-> [ 0.000402] (1:sendpid@Tremblay) Send of pid "1" done.
-> [ 0.000402] (1:sendpid@Tremblay) Process "1" killed.
-> [ 0.000804] (2:sendpid@Tremblay) Send of pid "2" done.
-> [ 0.000804] (4:killall@Tremblay) Killing process "2".
-> [ 0.000804] (2:sendpid@Tremblay) Process "2" killed.
-> [ 0.001206] (3:sendpid@Tremblay) Send of pid "3" done.
-> [ 0.001206] (4:killall@Tremblay) Killing process "3".
-> [ 0.001206] (3:sendpid@Tremblay) Process "3" killed.
-
-$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
-> [ 0.000000] (2:sendpid@Tremblay) Sending pid of "2".
-> [ 0.000000] (3:sendpid@Tremblay) Sending pid of "3".
-> [ 0.000000] (4:sendpid@Tremblay) Sending pid of "4".
-> [ 0.000402] (5:killall@Tremblay) Killing process "2".
-> [ 0.000402] (2:sendpid@Tremblay) Send of pid "2" done.
-> [ 0.000402] (2:sendpid@Tremblay) Process "2" killed.
-> [ 0.000804] (3:sendpid@Tremblay) Send of pid "3" done.
-> [ 0.000804] (5:killall@Tremblay) Killing process "3".
-> [ 0.000804] (3:sendpid@Tremblay) Process "3" killed.
-> [ 0.001206] (4:sendpid@Tremblay) Send of pid "4" done.
-> [ 0.001206] (5:killall@Tremblay) Killing process "4".
-> [ 0.001206] (4:sendpid@Tremblay) Process "4" killed.
--- /dev/null
+/* Copyright (c) 2009-2010, 2013-2015. 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 msg example");
+
+simgrid::s4u::MailboxPtr mailbox = simgrid::s4u::Mailbox::byName("mailbox");
+double comp_size = 1000;
+double comm_size = 100000;
+
+static int my_onexit(smx_process_exit_status_t status, int* pid)
+{
+ XBT_INFO("Process \"%d\" killed.", *pid);
+ return 0;
+}
+
+static void sendpid()
+{
+ int pid = simgrid::s4u::this_actor::pid();
+ simgrid::s4u::this_actor::onExit((int_f_pvoid_pvoid_t)my_onexit, &pid);
+
+ XBT_INFO("Sending pid of \"%d\".", pid);
+ simgrid::s4u::this_actor::send(mailbox, &pid, comm_size);
+ XBT_INFO("Send of pid \"%d\" done.", pid);
+
+ simgrid::s4u::this_actor::suspend();
+}
+
+static void killall()
+{
+ for (int i = 0; i < 3; i++) {
+ int* pid = static_cast<int*>(simgrid::s4u::this_actor::recv(mailbox));
+ XBT_INFO("Killing process \"%d\".", *pid);
+ simgrid::s4u::Actor::byPid(*pid)->kill();
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine* e = new simgrid::s4u::Engine(&argc, argv);
+ e->loadPlatform(argv[1]);
+
+ if (argc > 2)
+ simgrid::s4u::Actor::killAll(atoi(argv[2]));
+ else
+ simgrid::s4u::Actor::killAll();
+
+ simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+ simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+ simgrid::s4u::Actor::createActor("sendpid", simgrid::s4u::Host::by_name("Tremblay"), sendpid);
+ simgrid::s4u::Actor::createActor("killall", simgrid::s4u::Host::by_name("Tremblay"), killall);
+
+ e->run();
+
+ return 0;
+}
--- /dev/null
+$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "1".
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "2".
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "3".
+> [ 0.000402] (killall@Tremblay) Killing process "1".
+> [ 0.000402] (sendpid@Tremblay) Send of pid "1" done.
+> [ 0.000402] (sendpid@Tremblay) Process "1" killed.
+> [ 0.000804] (sendpid@Tremblay) Send of pid "2" done.
+> [ 0.000804] (killall@Tremblay) Killing process "2".
+> [ 0.000804] (sendpid@Tremblay) Process "2" killed.
+> [ 0.001206] (sendpid@Tremblay) Send of pid "3" done.
+> [ 0.001206] (killall@Tremblay) Killing process "3".
+> [ 0.001206] (sendpid@Tremblay) Process "3" killed.
+
+$ ./pid ${srcdir:=.}/../../../examples/platforms/small_platform.xml 2 "--log=root.fmt:[%10.6r]%e(%P@%h)%e%m%n"
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "2".
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "3".
+> [ 0.000000] (sendpid@Tremblay) Sending pid of "4".
+> [ 0.000402] (killall@Tremblay) Killing process "2".
+> [ 0.000402] (sendpid@Tremblay) Send of pid "2" done.
+> [ 0.000402] (sendpid@Tremblay) Process "2" killed.
+> [ 0.000804] (sendpid@Tremblay) Send of pid "3" done.
+> [ 0.000804] (killall@Tremblay) Killing process "3".
+> [ 0.000804] (sendpid@Tremblay) Process "3" killed.
+> [ 0.001206] (sendpid@Tremblay) Send of pid "4" done.
+> [ 0.001206] (killall@Tremblay) Killing process "4".
+> [ 0.001206] (sendpid@Tremblay) Process "4" killed.
teshsuite/java/CMakeLists.txt
teshsuite/mc/CMakeLists.txt
teshsuite/msg/CMakeLists.txt
+ teshsuite/s4u/CMakeLists.txt
teshsuite/simdag/CMakeLists.txt
teshsuite/simix/CMakeLists.txt
teshsuite/smpi/CMakeLists.txt