Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
710c6c4fe9639f1f4846563cd90d5a4bb854548b
[simgrid.git] / examples / cpp / actor-yield / s4u-actor-yield.cpp
1 /* Copyright (c) 2017-2021. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #include <simgrid/s4u.hpp>
7 namespace sg4 = simgrid::s4u;
8
9 /* This example does not much: It just spans over-polite actor that yield a large amount
10  * of time before ending.
11  *
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.
14  *
15  * It can also be used to benchmark our context-switching mechanism.
16  */
17 XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_actor_yield, "Messages specific for this s4u example");
18
19 static void yielder(long number_of_yields)
20 {
21   for (int i = 0; i < number_of_yields; i++)
22     sg4::this_actor::yield();
23   XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
24 }
25
26 int main(int argc, char* argv[])
27 {
28   sg4::Engine e(&argc, argv);
29
30   e.load_platform(argv[1]);             /* Load the platform description */
31
32   sg4::Actor::create("yielder", e.host_by_name("Tremblay"), yielder, 10);
33   sg4::Actor::create("yielder", e.host_by_name("Ruby"), yielder, 15);
34
35   e.run(); /* - Run the simulation */
36
37   return 0;
38 }