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