Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
8b24c42e48b235a17cb69ddfcf1d70654e3db44a
[simgrid.git] / win32_testsuite / borland / builder6 / simulation / xbt / context_usage / context_usage.c
1
2 /* log_usage - A test of normal usage of the log facilities                     */
3
4 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.                */
5
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.     */
8
9 #pragma hdrstop
10
11 #include "xbt/context.h"
12 #include "xbt/fifo.h"
13 #include "stdlib.h"
14 #include "stdio.h"
15
16 xbt_context_t cA = NULL;
17 xbt_context_t cB = NULL;
18 xbt_context_t cC = NULL;
19 xbt_fifo_t fifo = NULL;
20
21 void print_args(int argc, char** argv);
22 void print_args(int argc, char** argv)
23 {
24         int i ; 
25         
26         printf("args=<");
27         
28         for(i=0; i<argc; i++) 
29                 printf("%s ",argv[i]);
30         
31         printf(">\n");
32 }
33
34 int fA(int argc, char** argv);
35 int fA(int argc, char** argv)
36 {
37         printf("Here is fA: ");
38         print_args(argc,argv);
39         
40         printf("\tContext A: Yield\n");
41         xbt_context_yield();
42         
43         xbt_fifo_push(fifo,cB);
44         printf("\tPush context B from context A\n");
45         
46         printf("\tContext A: Yield\n");
47         xbt_context_yield();
48         printf("\tContext A : bye\n");
49         
50         return 0;
51 }
52
53 int fB(int argc, char** argv);
54 int fB(int argc, char** argv)
55 {
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");
61         xbt_context_yield();
62         printf("\tContext B : bye\n");
63         return 0;
64 }
65
66 int fC(int argc, char** argv);
67 int fC(int argc, char** argv)
68 {
69         printf("Here is fC: ");
70         print_args(argc,argv);
71         
72         
73         printf("\tContext C: Yield (and exit)\n");
74         xbt_context_yield();
75         
76         
77         return 0;
78 }
79 #pragma argsused
80
81 int main(int argc, char **argv)
82 {
83         xbt_context_t context = NULL;
84         
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");
87         
88         xbt_context_init();
89         
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);
93         
94         fifo = xbt_fifo_new();
95         
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);
103         
104         while((context=xbt_fifo_shift(fifo))) 
105         {
106                 printf("Context main: Yield\n");
107                 xbt_context_schedule(context);
108         }
109         
110         xbt_fifo_free(fifo);
111         xbt_context_exit();
112         
113         cA=cB=cC=NULL;
114         return 0;
115 }
116