Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Taking into account an old behavior modification of surf_solve
[simgrid.git] / testsuite / xbt / context_usage.c
1 #include "xbt/context.h"
2 #include "xbt/fifo.h"
3 #include "stdlib.h"
4 #include "stdio.h"
5
6 xbt_context_t cA = NULL;
7 xbt_context_t cB = NULL;
8 xbt_context_t cC = NULL;
9 xbt_fifo_t fifo = NULL;
10
11 void print_args(int argc, char** argv);
12 void print_args(int argc, char** argv)
13 {
14   int i ; 
15
16   printf("<");
17   for(i=0; i<argc; i++) 
18     printf("%s ",argv[i]);
19   printf(">\n");
20 }
21
22 int fA(int argc, char** argv);
23 int fA(int argc, char** argv)
24 {
25   printf("fA: ");
26   print_args(argc,argv);
27
28   printf("\tA: Yield\n");
29   xbt_context_yield();
30   printf("\tA: Yield\n");
31   xbt_context_yield();
32   printf("\tA : bye\n");
33
34   return 0;
35 }
36
37 int fB(int argc, char** argv);
38 int fB(int argc, char** argv)
39 {
40   printf("fB: ");
41   print_args(argc,argv);
42
43   printf("\tB: Yield\n");
44   xbt_context_yield();
45   xbt_fifo_push(fifo,cA);
46   printf("\tB->A\n");
47   printf("\tB: Yield\n");
48   xbt_context_yield();
49   printf("\tB : bye\n");
50
51   return 0;
52 }
53
54 int fC(int argc, char** argv);
55 int fC(int argc, char** argv)
56 {
57   printf("fC: ");
58   print_args(argc,argv);
59
60
61   printf("\tC: Yield\n");
62   xbt_context_yield();
63
64
65   return 0;
66 }
67
68 int main(int argc, char** argv)
69 {
70   xbt_context_t context = NULL;
71
72   xbt_context_init();
73
74   cA = xbt_context_new(fA, NULL, NULL, NULL, NULL, 0, NULL);
75   cB = xbt_context_new(fB, NULL, NULL, NULL, NULL, 0, NULL);
76   cC = xbt_context_new(fC, NULL, NULL, NULL, NULL, 0, NULL);
77
78   fifo = xbt_fifo_new();
79
80   xbt_context_start(cA);
81   printf("\tO->A\n");xbt_fifo_push(fifo,cA);
82   xbt_context_start(cB);
83   printf("\tO->B\n");xbt_fifo_push(fifo,cB);
84   xbt_context_start(cC);xbt_fifo_push(fifo,cC);
85   printf("\tO->C\n");xbt_fifo_push(fifo,cC);
86
87   while((context=xbt_fifo_shift(fifo))) {
88     printf("\tO:Yield\n");
89     xbt_context_schedule(context);
90   }
91
92   xbt_fifo_free(fifo);
93   xbt_context_exit();
94   
95   cA=cB=cC=NULL;
96   return 0;
97 }