doc/msg-tuto-src/masterworker4
examples/msg/actions-comm/actions-comm
examples/msg/actions-storage/actions-storage
+examples/msg/async-yield/async-yield
examples/msg/async-wait/async-wait
examples/msg/async-waitall/async-waitall
examples/msg/async-waitany/async-waitany
# C examples
-foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-wait async-waitall
+foreach(x actions-comm actions-storage app-masterworker app-pingpong app-pmm app-token-ring async-yield async-wait async-waitall
async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple cloud-two-tasks
dht-chord dht-pastry energy-consumption energy-onoff energy-pstate energy-ptask energy-vm platform-failures
io-file io-remote io-storage task-priority process-create process-kill process-migration process-suspend
set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.c ${CMAKE_CURRENT_SOURCE_DIR}/dht-kademlia/${file}.h)
endforeach()
-foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-wait
+foreach (file actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong async-yield async-wait
async-waitall async-waitany dht-chord dht-kademlia io-remote platform-properties
task-priority)
set(xml_files ${xml_files} ${CMAKE_CURRENT_SOURCE_DIR}/${file}/${file}_d.xml)
${CMAKE_CURRENT_SOURCE_DIR}/process-startkilltime/start_kill_d.xml PARENT_SCOPE)
foreach(x actions-comm actions-storage app-bittorrent app-chainsend app-masterworker app-pingpong app-token-ring
- async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple
+ async-yield async-wait async-waitall async-waitany cloud-capping cloud-masterworker cloud-migration cloud-simple
cloud-two-tasks dht-chord dht-pastry dht-kademlia platform-failures io-file io-remote io-storage task-priority
process-create process-kill process-migration process-suspend platform-properties synchro-semaphore
process-startkilltime)
--- /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/msg.h"
+
+/* This example does not much: It just spans over-polite processes that yield a large amount
+ * of time before ending.
+ *
+ * This serves as an example for the MSG_process_yield() function, with which a process can request
+ * to be rescheduled after the other processes that are ready at the current timestamp.
+ *
+ * It can also be used to benchmark our context-switching mechanism.
+ */
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_yield, "Messages specific for this msg example");
+
+/* Main function of the Yielder process */
+static int yielder(int argc, char* argv[])
+{
+ xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
+ long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
+
+ for (int i = 0; i < number_of_yields; i++)
+ MSG_process_yield();
+ XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
+ return 0;
+}
+
+int main(int argc, char* argv[])
+{
+ MSG_init(&argc, argv);
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s msg_platform.xml msg_deployment.xml\n",
+ argv[0], argv[0]);
+
+ MSG_create_environment(argv[1]); /* - Load the platform description */
+
+ MSG_function_register("yielder", yielder);
+ MSG_launch_application(argv[2]); /* - Deploy the sender and receiver processes */
+
+ msg_error_t res = MSG_main(); /* - Run the simulation */
+
+ return res != MSG_OK;
+}
--- /dev/null
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/async-yield ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../msg/async-yield/async-yield_d.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
+> [ 0.000000] (1:yielder@Tremblay) I yielded 10 times. Goodbye now!
+> [ 0.000000] (2:yielder@Ruby) I yielded 15 times. Goodbye now!
--- /dev/null
+<?xml version='1.0'?>
+<!DOCTYPE platform SYSTEM "http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd">
+<platform version="4">
+ <process host="Tremblay" function="yielder">
+ <argument value="10"/> <!-- Number of yields to do -->
+ </process>
+ <process host="Ruby" function="yielder">
+ <argument value="15"/> <!-- Number of yields to do -->
+ </process>
+</platform>