1 /* Copyright (c) 2017. 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/msg.h"
8 /* This example does not much: It just spans over-polite processes that yield a large amount
9 * of time before ending.
11 * This serves as an example for the MSG_process_yield() function, with which a process can request
12 * to be rescheduled after the other processes that are ready at the current timestamp.
14 * It can also be used to benchmark our context-switching mechanism.
17 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_async_yield, "Messages specific for this msg example");
19 /* Main function of the Yielder process */
20 static int yielder(int argc, char* argv[])
22 xbt_assert(argc == 2, "The sender function expects 1 arguments from the XML deployment file");
23 long number_of_yields = xbt_str_parse_int(argv[1], "Invalid amount of yields: %s"); /* - number of yields */
25 for (int i = 0; i < number_of_yields; i++)
27 XBT_INFO("I yielded %ld times. Goodbye now!", number_of_yields);
31 int main(int argc, char* argv[])
33 MSG_init(&argc, argv);
34 xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n"
35 "\tExample: %s msg_platform.xml msg_deployment.xml\n",
38 MSG_create_environment(argv[1]); /* - Load the platform description */
40 MSG_function_register("yielder", yielder);
41 MSG_launch_application(argv[2]); /* - Deploy the sender and receiver processes */
43 msg_error_t res = MSG_main(); /* - Run the simulation */