Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[simdag/cycle] delete the function acyclic_graph_detection because the
[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
80 #pragma argsused
81
82 int main(int argc, char **argv)
83 {
84   xbt_context_t context = NULL;
85
86   printf("XXX Test the simgrid context API\n");
87   printf
88       ("    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");
101   xbt_fifo_push(fifo, cA);
102   xbt_context_start(cB);
103   printf("\tPush context 'B' from context 'main'\n");
104   xbt_fifo_push(fifo, cB);
105   xbt_context_start(cC);
106   xbt_fifo_push(fifo, cC);
107   printf("\tPush context 'C' from context 'main'\n");
108   xbt_fifo_push(fifo, cC);
109
110   while ((context = xbt_fifo_shift(fifo))) {
111     printf("Context main: Yield\n");
112     xbt_context_schedule(context);
113   }
114
115   xbt_fifo_free(fifo);
116   xbt_context_exit();
117
118   cA = cB = cC = NULL;
119   return 0;
120 }