6 #include "xbt/context.h"
9 xbt_context_t cA = NULL;
10 xbt_context_t cB = NULL;
11 xbt_context_t cC = NULL;
12 xbt_fifo_t fifo = NULL;
14 void print_args(int argc, char** argv);
15 void print_args(int argc, char** argv)
21 printf("%s ",argv[i]);
25 int fA(int argc, char** argv);
26 int fA(int argc, char** argv)
28 printf("Here is fA: ");
29 print_args(argc,argv);
31 printf("\tContext A: Yield\n");
32 // xbt_context_yield(); // FIXME: yielding to itself fails, no idea why
34 xbt_fifo_push(fifo,cB);
35 printf("\tPush context B from context A\n");
37 printf("\tContext A: Yield\n");
39 printf("\tContext A : bye\n");
44 int fB(int argc, char** argv);
45 int fB(int argc, char** argv)
47 printf("Here is fB: ");
48 print_args(argc,argv);
50 // printf("\tContext B: Yield\n");
51 // xbt_context_yield();
52 xbt_fifo_push(fifo,cA);
53 printf("\tPush context A from context B\n");
54 printf("\tContext B: Yield\n");
56 printf("\tContext B : bye\n");
61 int fC(int argc, char** argv);
62 int fC(int argc, char** argv)
64 printf("Here is fC: ");
65 print_args(argc,argv);
68 printf("\tContext C: Yield (and exit)\n");
79 int main(int argc, char** argv)
81 xbt_context_t context = NULL;
83 printf("XXX Test the simgrid context API\n");
84 printf(" If it fails, try another context backend.\n For example, to force the pthread backend, use:\n ./configure --with-context=pthread\n\n");
86 xbt_init(&argc, argv);
88 cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL);
89 cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL);
90 cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL);
92 fifo = xbt_fifo_new();
94 printf("Here is context 'main'\n");
95 xbt_context_start(cA);
96 printf("\tPush context 'A' from context 'main'\n");xbt_fifo_push(fifo,cA);
97 xbt_context_start(cB);
98 printf("\tPush context 'B' from context 'main'\n");xbt_fifo_push(fifo,cB);
99 xbt_context_start(cC);xbt_fifo_push(fifo,cC);
100 printf("\tPush context 'C' from context 'main'\n");xbt_fifo_push(fifo,cC);
102 while((context=xbt_fifo_shift(fifo))) {
103 printf("Context main: Yield\n");
104 xbt_context_schedule(context);