1 /***************************** Bugged2 ****************************************/
2 /* This example implements a centralized mutual exclusion algorithm. */
3 /* One client stay always in critical section */
4 /* LTL property checked : !(GFcs) */
5 /******************************************************************************/
9 #include "xbt/automaton.h"
10 #include "bugged2_liveness.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(bugged3, "my log messages");
21 int coordinator(int argc, char **argv);
22 int client(int argc, char **argv);
24 int coordinator(int argc, char *argv[])
26 int CS_used = 0; // initially the CS is idle
29 msg_task_t task = NULL;
30 MSG_task_receive(&task, "coordinator");
31 const char *kind = MSG_task_get_name(task); //is it a request or a release?
32 if (!strcmp(kind, "request")) { // that's a request
33 char *req = MSG_task_get_data(task);
35 XBT_INFO("CS already used.");
36 msg_task_t answer = MSG_task_create("not grant", 0, 1000, NULL);
37 MSG_task_send(answer, req);
39 } else { // can serve it immediatly
40 XBT_INFO("CS idle. Grant immediatly");
41 msg_task_t answer = MSG_task_create("grant", 0, 1000, NULL);
42 MSG_task_send(answer, req);
45 } else { // that's a release. Check if someone was waiting for the lock
46 XBT_INFO("CS release. resource now idle");
49 MSG_task_destroy(task);
56 int client(int argc, char *argv[])
58 int my_pid = MSG_process_get_PID(MSG_process_self());
59 char *my_mailbox = bprintf("%s", argv[1]);
64 XBT_INFO("Client (%s) asks the request", my_mailbox);
65 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox),
68 msg_task_t answer = NULL;
69 MSG_task_receive(&answer, my_mailbox);
71 kind = MSG_task_get_name(answer);
73 if (!strcmp(kind, "grant")) {
75 XBT_INFO("Client (%s) got the answer (grant). Sleep a bit and release it", my_mailbox);
77 if(!strcmp(my_mailbox, "1"))
82 XBT_INFO("Client (%s) got the answer (not grant). Try again", my_mailbox);
86 MSG_task_destroy(answer);
89 MSG_process_sleep(my_pid);
95 int main(int argc, char *argv[])
98 MSG_init(&argc, argv);
100 MSG_config("model-check/property","promela_bugged2_liveness");
101 MC_automaton_new_propositional_symbol("cs", &predCS);
103 MSG_create_environment("../msg_platform.xml");
104 MSG_function_register("coordinator", coordinator);
105 MSG_function_register("client", client);
106 MSG_launch_application("deploy_bugged2_liveness.xml");