Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
67f5f87182f69da3f6cd6000351ae2d0ec1e4b8d
[simgrid.git] / examples / msg / mc / example_automaton.c
1 #include "xbt/automaton.h"
2 #include "xbt/automatonparse_promela.h"
3 #include "example_automaton.h"
4 #include "msg/msg.h"
5
6 #include "y.tab.c"
7
8 #define N 3
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "Example with automaton");
11
12 extern xbt_automaton_t automaton;
13
14
15 int d=1;
16 int r=0;
17 int e=1;
18
19 int predD(){
20   return d;
21 }
22
23 int predR(){
24   return r;
25 }
26
27 int predE(){
28   return e;
29 }
30
31 int server(int argc, char *argv[])
32 {
33   m_task_t task = NULL;
34   int count = 0;
35   while (count < N) {
36     if (task) {
37       MSG_task_destroy(task);
38       task = NULL;
39     }
40     MSG_task_receive(&task, "mymailbox");
41     count++;
42     //e++;
43     //e=e%2;
44   }
45   //MC_assert(atoi(MSG_task_get_name(task)) == 3);
46
47   XBT_INFO("OK");
48   return 0;
49 }
50
51 int client(int argc, char *argv[])
52 {
53
54   m_task_t task =
55       MSG_task_create(argv[1], 0 /*comp cost */ , 10000 /*comm size */ ,
56                       NULL /*arbitrary data */ );
57
58   MSG_task_send(task, "mymailbox");
59   
60   XBT_INFO("Sent!");
61   return 0;
62 }
63
64
65
66 int main(int argc, char **argv){
67   init();
68   yyparse();
69   automaton = get_automaton();
70   xbt_propositional_symbol_t ps = xbt_new_propositional_symbol(automaton,"d", &predD); 
71   ps = xbt_new_propositional_symbol(automaton,"e", &predE); 
72   ps = xbt_new_propositional_symbol(automaton,"r", &predR); 
73   
74   //display_automaton();
75
76   MSG_global_init(&argc, argv);
77
78   MSG_create_environment("platform.xml");
79
80   MSG_function_register("server", server);
81
82   MSG_function_register("client", client);
83
84   MSG_launch_application("deploy_bugged1.xml");
85
86   MSG_main_with_automaton(automaton);
87
88   MSG_clean();
89
90   return 0;
91
92 }