3 #include "xbt/automaton.h"
4 #include "xbt/automatonparse_promela.h"
5 #include "bugged2_liveness.h"
8 XBT_LOG_NEW_DEFAULT_CATEGORY(example_liveness_with_cycle, "my log messages");
33 int coordinator(int argc, char *argv[])
35 xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);
40 MSG_task_receive(&task, "coordinator");
41 const char *kind = MSG_task_get_name(task);
42 if (!strcmp(kind, "request")) {
43 char *req = MSG_task_get_data(task);
45 XBT_INFO("CS already used. Queue the request");
46 xbt_dynar_push(requests, &req);
48 m_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
49 MSG_task_send(answer, req);
51 XBT_INFO("CS idle. Grant immediatly");
54 if (xbt_dynar_length(requests) > 0) {
55 XBT_INFO("CS release. Grant to queued requests");
57 xbt_dynar_pop(requests, &req);
58 MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
60 XBT_INFO("CS_realase, ressource now idle");
65 MSG_task_destroy(task);
73 int producer(int argc, char *argv[])
76 char * my_mailbox = bprintf("%s", argv[1]);
81 const char *mess = "message";
84 XBT_INFO("Producer ask the request");
85 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
88 m_task_t grant = NULL;
89 MSG_task_receive(&grant, my_mailbox);
90 MSG_task_destroy(grant);
94 /* Push message (size of buffer = 1) */
95 buffer = strdup(mess);
98 MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator");
112 int consumer(int argc, char *argv[])
115 char * my_mailbox = bprintf("%s", argv[1]);
122 XBT_INFO("Consumer ask the request");
123 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
125 /* Wait the answer */
126 m_task_t grant = NULL;
127 MSG_task_receive(&grant, my_mailbox);
128 MSG_task_destroy(grant);
133 mess = malloc(8*sizeof(char));
134 mess = strdup(buffer);
138 MSG_task_send(MSG_task_create("release", 0, 1000, my_mailbox), "coordinator");
140 /* Display message */
141 XBT_INFO("Message : %s", mess);
142 if(strcmp(mess, "") != 0)
159 int main(int argc, char *argv[])
162 buffer = malloc(8*sizeof(char));
167 automaton = get_automaton();
168 xbt_new_propositional_symbol(automaton,"pready", &predPready);
169 xbt_new_propositional_symbol(automaton,"cready", &predCready);
170 xbt_new_propositional_symbol(automaton,"consume", &predConsume);
171 xbt_new_propositional_symbol(automaton,"produce", &predProduce);
173 MSG_global_init(&argc, argv);
174 MSG_create_environment("../msg_platform.xml");
175 MSG_function_register("coordinator", coordinator);
176 MSG_function_register("consumer", consumer);
177 MSG_function_register("producer", producer);
178 MSG_launch_application("deploy_bugged2_liveness.xml");
179 MSG_main_liveness(automaton, argv[0]);