1 /* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved. */
3 /* This program is free software; you can redistribute it and/or modify it
4 * under the terms of the license (GNU LGPL) which comes with this package. */
6 #include <simgrid/s4u.hpp>
7 namespace sg4 = simgrid::s4u;
9 /* This example does not much: It just spans over-polite actor that yield a large amount
10 * of time before ending.
12 * This serves as an example for the sg4::this_actor::yield() function, with which an actor can request
13 * to be rescheduled after the other actor that are ready at the current timestamp.
15 * It can also be used to benchmark our context-switching mechanism.
17 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
18 /* Main function of the Yielder actor */
20 long number_of_yields;
23 explicit yielder(std::vector<std::string> args) { number_of_yields = std::stol(args[1]); }
24 void operator()() const
26 for (int i = 0; i < number_of_yields; i++)
27 sg4::this_actor::yield();
28 XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
32 int main(int argc, char* argv[])
34 sg4::Engine e(&argc, argv);
36 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
37 "\tExample: %s platform.xml deployment.xml\n",
40 e.load_platform(argv[1]); /* Load the platform description */
41 e.register_actor<yielder>("yielder"); /* Register the class representing the actors */
43 e.load_deployment(argv[2]);
45 e.run(); /* - Run the simulation */