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/actor.h"
7 #include "simgrid/engine.h"
9 #include "xbt/asserts.h"
13 /* This example does not much: It just spans over-polite actors that yield a large amount
14 * of time before ending.
16 * This serves as an example for the sg_actor_yield() function, with which an actor can request
17 * to be rescheduled after the other actors that are ready at the current timestamp.
19 * It can also be used to benchmark our context-switching mechanism.
22 XBT_LOG_NEW_DEFAULT_CATEGORY(actor_yield, "Messages specific for this example");
24 /* Main function of the Yielder actor */
25 static void yielder(int argc, char* argv[])
27 xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
28 long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
30 for (int i = 0; i < number_of_yields; i++)
32 XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
35 int main(int argc, char* argv[])
37 simgrid_init(&argc, argv);
39 "Usage: %s platform_file deployment_file\n"
40 "\tExample: %s msg_platform.xml msg_deployment.xml\n",
43 simgrid_load_platform(argv[1]); /* - Load the platform description */
45 simgrid_register_function("yielder", yielder);
46 simgrid_load_deployment(argv[2]); /* - Deploy the sender and receiver actors */