Logo AND Algorithmique Numérique Distribuée

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