foreach (example actions-comm actions-storage
actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend actor-priority
app-masterworker app-pingpong app-token-ring
- async-wait async-waitany async-waitall
+ async-wait async-waitany async-waitall actor-yield
energy-link
plugin-hostload io mutex)
add_executable (s4u-${example} ${example}/s4u-${example}.cpp)
set(examples_src ${examples_src} PARENT_SCOPE)
set(tesh_files ${tesh_files} ${CMAKE_CURRENT_SOURCE_DIR}/app-bittorrent/s4u-app-bittorrent.tesh
${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord.tesh
+ ${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield.tesh
${CMAKE_CURRENT_SOURCE_DIR}/actor-priority/s4u-actor-priority.tesh
${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime.tesh
${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait.tesh
${CMAKE_CURRENT_SOURCE_DIR}/async-waitany/s4u-async-waitany_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-waitall/s4u-async-waitall_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/async-wait/s4u-async-wait_d.xml
+ ${CMAKE_CURRENT_SOURCE_DIR}/actor-yield/s4u-actor-yield_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/dht-chord/s4u-dht-chord_d.xml
${CMAKE_CURRENT_SOURCE_DIR}/actor-lifetime/s4u-actor-lifetime_d.xml
PARENT_SCOPE)
foreach(example actions-comm actions-storage
actor-create actor-daemon actor-execute actor-kill actor-lifetime actor-migration actor-suspend
app-bittorrent app-masterworker app-pingpong app-token-ring
- async-wait async-waitall async-waitany actor-priority
+ async-wait async-waitall async-waitany actor-priority actor-yield
dht-chord
energy-link
plugin-hostload io mutex)
@ref examples/s4u/actor-migration/s4u-actor-migration.cpp \n
Actors can move or be moved from a host to another with the @ref migrate method.
+ - <b>Yielding to other actor</b>.
+ @ref examples/s4u/actor-yield/s4u-actor-yield.c\n
+ The @ref yield function interrupts the execution of the
+ current actor, leaving a chance to run to the other actor
+ that are ready to run at the exact same timestamp
+
@section s4u_ex_synchro Inter-Actor Synchronization
- <b>Mutex: </b> @ref examples/s4u/mutex/s4u-mutex.cpp \n
--- /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"
+
+/* This example does not much: It just spans over-polite actor that yield a large amount
+* of time before ending.
+*
+* This serves as an example for the s4u-actor-yield() function, with which an actor can request
+* to be rescheduled after the other actor that are ready at the current timestamp.
+*
+* It can also be used to benchmark our context-switching mechanism.
+*/
+XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
+/* Main function of the Yielder process */
+class yielder {
+ long number_of_yields;
+public:
+ explicit yielder() = default;
+ explicit yielder(std::vector<std::string> args)
+{
+ number_of_yields = std::stod(args[1]);
+}
+void operator()()
+{
+ for (int i = 0; i < number_of_yields; i++)
+ simgrid::s4u::this_actor::yield();
+ XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
+}
+};
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+
+ xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
+ "\tExample: %s platform.xml deployment.xml\n",
+ argv[0], argv[0]);
+
+ e.loadPlatform(argv[1]); /* - Load the platform description */
+ e.registerFunction<yielder>("yielder");
+ std::vector<std::string> args;
+
+ e.loadDeployment(argv[2]);
+
+ e.run(); /* - Run the simulation */
+
+ return 0;
+}
--- /dev/null
+#! ./tesh
+
+$ $SG_TEST_EXENV ${bindir:=.}/s4u-actor-yield ${srcdir:=.}/small_platform_fatpipe.xml ${srcdir:=.}/../s4u/actor-yield/s4u-actor-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.1">
+ <actor host="Tremblay" function="yielder">
+ <argument value="10"/> <!-- Number of yields to do -->
+ </actor>
+ <actor host="Ruby" function="yielder">
+ <argument value="15"/> <!-- Number of yields to do -->
+ </actor>
+</platform>
/** Resume a suspended actor by resuming the task on which it was waiting for the completion. */
void resume();
-
+
+ void yield();
+
/** Returns true if the actor is suspended. */
int isSuspended();
/** @brief Suspend the actor. */
XBT_PUBLIC(void) suspend();
+/** @brief yield the actor. */
+XBT_PUBLIC(void) yield();
+
/** @brief Resume the actor. */
XBT_PUBLIC(void) resume();
simcall_process_sleep(duration);
}
+void yield()
+{
+ simgrid::simix::kernelImmediate([] { /* do nothing*/ });
+}
+
XBT_PUBLIC(void) sleep_until(double timeout)
{
double now = SIMIX_get_clock();