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)
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");
81 int main(int argc, char **argv)
83 xbt_context_t context = NULL;
85 printf("XXX Test the simgrid context API\n");
86 printf(" If it fails, try another context backend.\n For example, to force the pthread backend, use:\n ./configure --with-context=pthread\n\n");
90 cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL);
91 cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL);
92 cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL);
94 fifo = xbt_fifo_new();
96 printf("Here is context 'main'\n");
97 xbt_context_start(cA);
98 printf("\tPush context 'A' from context 'main'\n");xbt_fifo_push(fifo,cA);
99 xbt_context_start(cB);
100 printf("\tPush context 'B' from context 'main'\n");xbt_fifo_push(fifo,cB);
101 xbt_context_start(cC);xbt_fifo_push(fifo,cC);
102 printf("\tPush context 'C' from context 'main'\n");xbt_fifo_push(fifo,cC);
104 while((context=xbt_fifo_shift(fifo)))
106 printf("Context main: Yield\n");
107 xbt_context_schedule(context);