2 /* log_usage - A test of normal usage of the log facilities */
4 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "xbt/context.h"
16 xbt_context_t cA = NULL;
17 xbt_context_t cB = NULL;
18 xbt_context_t cC = NULL;
19 xbt_fifo_t fifo = NULL;
21 void print_args(int argc, char **argv);
22 void print_args(int argc, char **argv)
28 for (i = 0; i < argc; i++)
29 printf("%s ", argv[i]);
34 int fA(int argc, char **argv);
35 int fA(int argc, char **argv)
37 printf("Here is fA: ");
38 print_args(argc, argv);
40 printf("\tContext A: Yield\n");
43 xbt_fifo_push(fifo, cB);
44 printf("\tPush context B from context A\n");
46 printf("\tContext A: Yield\n");
48 printf("\tContext A : bye\n");
53 int fB(int argc, char **argv);
54 int fB(int argc, char **argv)
56 printf("Here is fB: ");
57 print_args(argc, argv);
58 xbt_fifo_push(fifo, cA);
59 printf("\tPush context A from context B\n");
60 printf("\tContext B: Yield\n");
62 printf("\tContext B : bye\n");
66 int fC(int argc, char **argv);
67 int fC(int argc, char **argv)
69 printf("Here is fC: ");
70 print_args(argc, argv);
73 printf("\tContext C: Yield (and exit)\n");
82 int main(int argc, char **argv)
84 xbt_context_t context = NULL;
86 printf("XXX Test the simgrid context API\n");
88 (" If it fails, try another context backend.\n For example, to force the pthread backend, use:\n ./configure --with-context=pthread\n\n");
92 cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL);
93 cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL);
94 cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL);
96 fifo = xbt_fifo_new();
98 printf("Here is context 'main'\n");
99 xbt_context_start(cA);
100 printf("\tPush context 'A' from context 'main'\n");
101 xbt_fifo_push(fifo, cA);
102 xbt_context_start(cB);
103 printf("\tPush context 'B' from context 'main'\n");
104 xbt_fifo_push(fifo, cB);
105 xbt_context_start(cC);
106 xbt_fifo_push(fifo, cC);
107 printf("\tPush context 'C' from context 'main'\n");
108 xbt_fifo_push(fifo, cC);
110 while ((context = xbt_fifo_shift(fifo))) {
111 printf("Context main: Yield\n");
112 xbt_context_schedule(context);