ADD_TEST(tesh-msg-host-on-off-ucontext ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.tesh)
endif()
-
ADD_TEST(tesh-msg-task-destroy-cancel-thread ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:thread --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.tesh)
if(HAVE_RAWCTX)
ADD_TEST(tesh-msg-task-destroy-cancel-raw ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:raw --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.tesh)
ADD_TEST(tesh-msg-task-destroy-cancel-ucontext ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.tesh)
endif()
+ ADD_TEST(tesh-msg-process-thread ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:thread --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process.tesh)
+ if(HAVE_RAWCTX)
+ ADD_TEST(tesh-msg-process-raw ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:raw --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process.tesh)
+ endif()
+ if(CONTEXT_UCONTEXT)
+ ADD_TEST(tesh-msg-process-ucontext ${TESH_COMMAND} ${TESH_OPTION} --cfg contexts/factory:ucontext --setenv srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite --cd ${CMAKE_BINARY_DIR}/teshsuite ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process.tesh)
+ endif()
+
+
# these tests need the assertion mechanism
# exclude them from memcheck, as they normally die, leaving lots of unfree'd objects
IF(enable_debug AND NOT enable_memcheck)
int argc, char **argv,
xbt_dict_t properties,
int auto_restart){
- SIMIX_process_create(process, name, code, data, hostname,
- kill_time, argc, argv, properties, auto_restart);
+ SIMIX_process_create_with_parent(process, name, code, data, hostname,
+ kill_time, argc, argv, properties, auto_restart,
+ simcall->issuer);
}
/**
* \brief Internal function to create a process.
int argc, char **argv,
xbt_dict_t properties,
int auto_restart) {
-
+ SIMIX_process_create_with_parent(process, name, code, data, hostname,
+ kill_time, argc, argv, properties, auto_restart, NULL);
+}
+
+void SIMIX_process_create_with_parent(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties,
+ int auto_restart,
+ smx_process_t parent_process) {
*process = NULL;
smx_host_t host = SIMIX_host_get_by_name(hostname);
(*process)->comms = xbt_fifo_new();
(*process)->simcall.issuer = *process;
- if (SIMIX_process_self()) {
- (*process)->ppid = SIMIX_process_get_PID(SIMIX_process_self());
+ if (parent_process) {
+ (*process)->ppid = SIMIX_process_get_PID(parent_process);
} else {
(*process)->ppid = -1;
}
{
smx_simcall_t simcall;
e_smx_state_t state;
-
+ smx_process_t issuer;
xbt_assert(action->type == SIMIX_ACTION_SLEEP);
while ((simcall = xbt_fifo_shift(action->simcalls))) {
simcall_process_sleep__set__result(simcall, state);
simcall->issuer->waiting_action = NULL;
SIMIX_simcall_answer(simcall);
+ issuer = simcall->issuer;
}
+
SIMIX_process_sleep_destroy(action);
+ if (issuer->suspended)
+ simcall_process_suspend(issuer);
}
void SIMIX_process_sleep_destroy(smx_action_t action)
int argc, char **argv,
xbt_dict_t properties,
int auto_restart);
+void SIMIX_process_create_with_parent(smx_process_t *process,
+ const char *name,
+ xbt_main_func_t code,
+ void *data,
+ const char *hostname,
+ double kill_time,
+ int argc, char **argv,
+ xbt_dict_t properties,
+ int auto_restart,
+ smx_process_t parent_process);
void SIMIX_process_runall(void);
void SIMIX_process_kill(smx_process_t process, smx_process_t issuer);
void SIMIX_process_killall(smx_process_t issuer, int reset_pid);
add_executable(pid ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/pid.c)
add_executable(host_on_off ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/host_on_off.c)
add_executable(task_destroy_cancel ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/task_destroy_cancel.c)
+add_executable(process ${CMAKE_HOME_DIRECTORY}/teshsuite/msg/process.c)
### Add definitions for compile
target_link_libraries(get_sender simgrid)
target_link_libraries(host_on_off simgrid)
target_link_libraries(task_destroy_cancel simgrid)
+target_link_libraries(process simgrid)
if(NOT WIN32)
target_link_libraries(pid simgrid m pthread)
else()
${CMAKE_CURRENT_SOURCE_DIR}/pid.tesh
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.tesh
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/process.tesh
PARENT_SCOPE
)
set(xml_files
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off_p.xml
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel_p.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/process.xml
PARENT_SCOPE
)
set(teshsuite_src
${CMAKE_CURRENT_SOURCE_DIR}/pid.c
${CMAKE_CURRENT_SOURCE_DIR}/host_on_off.c
${CMAKE_CURRENT_SOURCE_DIR}/task_destroy_cancel.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/process.c
PARENT_SCOPE
)
set(bin_files
> [Tremblay:master:(1) 3.710127] [msg_test/INFO] Goodbye now!
> [Jupiter:slave:(3) 3.710127] [msg_test/INFO] I'm done. See you!
> [3.710127] [msg_test/INFO] Simulation time 3.71013
+
--- /dev/null
+/* Copyright (c) 2010-2014. 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 <stdio.h>
+#include "msg/msg.h" /* Yeah! If you want to use msg, you need to include msg/msg.h */
+#include "xbt/sysdep.h" /* calloc, printf */
+
+/* Create a log channel to have nice outputs. */
+#include "xbt/log.h"
+#include "xbt/asserts.h"
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test,
+ "Messages specific for this msg example");
+
+int master(int argc, char *argv[]);
+int slave(int argc, char *argv[]);
+
+/** Emitter function */
+int master(int argc, char *argv[])
+{
+ xbt_swag_t process_list = MSG_host_get_process_list(MSG_host_self());
+ msg_process_t process = NULL;
+ MSG_process_sleep(1);
+ xbt_swag_foreach(process, process_list) {
+ XBT_INFO("Process(pid=%d, ppid=%d, name=%s)", MSG_process_get_PID(process), MSG_process_get_PPID(process), MSG_process_get_name(process));
+ if (MSG_process_self_PID()!=MSG_process_get_PID(process))
+ MSG_process_kill(process);
+ }
+ process = MSG_process_create("slave from master", slave, NULL, MSG_host_self());
+ MSG_process_sleep(2);
+
+ XBT_INFO("Suspend Process(pid=%d)", MSG_process_get_PID(process));
+ MSG_process_suspend(process);
+
+ XBT_INFO("Process(pid=%d) is %ssuspended"
+ ,MSG_process_get_PID(process)
+ ,(MSG_process_is_suspended(process)) ? "" : "not ");
+ MSG_process_sleep(2);
+
+ XBT_INFO("Resume Process(pid=%d)", MSG_process_get_PID(process));
+ MSG_process_resume(process);
+
+ XBT_INFO("Process(pid=%d) is %ssuspended"
+ ,MSG_process_get_PID(process)
+ ,(MSG_process_is_suspended(process)) ? "" : "not ");
+ MSG_process_sleep(2);
+ MSG_process_kill(process);
+
+ XBT_INFO("Goodbye now!");
+ return 0;
+} /* end_of_master */
+
+/** Receiver function */
+int slave(int argc, char *argv[])
+{
+ MSG_process_sleep(.5);
+ XBT_INFO("Slave started (PID:%d, PPID:%d)", MSG_process_self_PID(), MSG_process_self_PPID());
+ while(1){
+ XBT_INFO("Plop i am %ssuspended", (MSG_process_is_suspended(MSG_process_self())) ? "" : "not ");
+ MSG_process_sleep(1);
+ //MSG_process_suspend(MSG_process_self());
+ }
+ XBT_INFO("I'm done. See you!");
+ return 0;
+} /* end_of_slave */
+
+/** Main function */
+int main(int argc, char *argv[])
+{
+ msg_error_t res;
+ const char *platform_file;
+ const char *application_file;
+
+ MSG_init(&argc, argv);
+ if (argc < 2) {
+ printf("Usage: %s platform_file deployment_file\n", argv[0]);
+ printf("example: %s msg_platform.xml msg_deployment.xml\n", argv[0]);
+ exit(1);
+ }
+ platform_file = argv[1];
+ application_file = argv[1];
+
+ /* MSG_config("workstation/model","KCCFLN05"); */
+ { /* Simulation setting */
+ MSG_create_environment(platform_file);
+ }
+ { /* Application deployment */
+ MSG_function_register("master", master);
+ MSG_function_register("slave", slave);
+
+ MSG_launch_application(application_file);
+ }
+ res = MSG_main();
+
+ XBT_INFO("Simulation time %g", MSG_get_clock());
+
+ if (res == MSG_OK)
+ return 0;
+ else
+ return 1;
+} /* end_of_main */
--- /dev/null
+
+$ msg/process ${srcdir:=.}/msg/process.xml
+> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Slave started (PID:2, PPID:0)
+> [Tremblay:slave:(2) 0.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=1, ppid=0, name=master)
+> [Tremblay:master:(1) 1.000000] [msg_test/INFO] Process(pid=2, ppid=0, name=slave)
+> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Slave started (PID:3, PPID:1)
+> [Tremblay:slave from master:(3) 1.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 2.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Suspend Process(pid=3)
+> [Tremblay:master:(1) 3.000000] [msg_test/INFO] Process(pid=3) is suspended
+> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Resume Process(pid=3)
+> [Tremblay:master:(1) 5.000000] [msg_test/INFO] Process(pid=3) is not suspended
+> [Tremblay:slave from master:(3) 5.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:slave from master:(3) 6.500000] [msg_test/INFO] Plop i am not suspended
+> [Tremblay:master:(1) 7.000000] [msg_test/INFO] Goodbye now!
+> [7.000000] [msg_test/INFO] Simulation time 7
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid.dtd">
+<platform version="3">
+ <!-- The hosts -->
+ <AS id="AS0" routing="Full">
+ <host id="Tremblay" power="98.095Mf"/>
+ </AS>
+
+ <!-- The master process (with some arguments) -->
+ <process host="Tremblay" function="master">
+ </process>
+
+ <!-- The slave processes (with mailbox to listen on as argument) -->
+ <process host="Tremblay" function="slave">
+ </process>
+ </platform>
\ No newline at end of file