4 /* log_usage - A test of normal usage of the log facilities */
6 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "xbt/context.h"
18 xbt_context_t cA = NULL;
19 xbt_context_t cB = NULL;
20 xbt_context_t cC = NULL;
21 xbt_fifo_t fifo = NULL;
23 void print_args(int argc, char** argv);
24 void print_args(int argc, char** argv)
31 printf("%s ",argv[i]);
36 int fA(int argc, char** argv);
37 int fA(int argc, char** argv)
39 printf("Here is fA: ");
40 print_args(argc,argv);
42 printf("\tContext A: Yield\n");
45 xbt_fifo_push(fifo,cB);
46 printf("\tPush context B from context A\n");
48 printf("\tContext A: Yield\n");
50 printf("\tContext A : bye\n");
55 int fB(int argc, char** argv);
56 int fB(int argc, char** argv)
58 printf("Here is fB: ");
59 print_args(argc,argv);
60 xbt_fifo_push(fifo,cA);
61 printf("\tPush context A from context B\n");
62 printf("\tContext B: Yield\n");
64 printf("\tContext B : bye\n");
68 int fC(int argc, char** argv);
69 int fC(int argc, char** argv)
71 printf("Here is fC: ");
72 print_args(argc,argv);
75 printf("\tContext C: Yield (and exit)\n");
83 int main(int argc, char **argv)
85 xbt_context_t context = NULL;
87 printf("XXX Test the simgrid context API\n");
88 printf(" 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");xbt_fifo_push(fifo,cA);
101 xbt_context_start(cB);
102 printf("\tPush context 'B' from context 'main'\n");xbt_fifo_push(fifo,cB);
103 xbt_context_start(cC);xbt_fifo_push(fifo,cC);
104 printf("\tPush context 'C' from context 'main'\n");xbt_fifo_push(fifo,cC);
106 while((context=xbt_fifo_shift(fifo)))
108 printf("Context main: Yield\n");
109 xbt_context_schedule(context);