1 /***************** Centralized Mutual Exclusion Algorithm *********************/
2 /* This example implements a centralized mutual exclusion algorithm. */
3 /* CS requests of client 1 not satisfied */
4 /* LTL property checked : G(r->F(cs)); (r=request of CS, cs=CS ok) */
5 /******************************************************************************/
9 #include "xbt/automaton.h"
10 #include "bugged1_liveness.h"
12 XBT_LOG_NEW_DEFAULT_CATEGORY(bugged1_liveness, "my log messages");
26 int coordinator(int argc, char *argv[])
30 msg_task_t task = NULL, answer = NULL;
33 MSG_task_receive(&task, "coordinator");
34 const char *kind = MSG_task_get_name(task);
35 if (!strcmp(kind, "request")) {
36 char *req = MSG_task_get_data(task);
38 XBT_INFO("CS already used.");
40 if(strcmp(req, "2") == 0){
41 XBT_INFO("CS idle. Grant immediatly");
42 answer = MSG_task_create("grant", 0, 1000, NULL);
43 MSG_task_send(answer, req);
49 XBT_INFO("CS release. resource now idle");
52 MSG_task_destroy(task);
60 int client(int argc, char *argv[])
62 int my_pid = MSG_process_get_PID(MSG_process_self());
64 char *my_mailbox = bprintf("%s", argv[1]);
65 msg_task_t grant = NULL, release = NULL;
70 XBT_INFO("Ask the request");
71 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
73 if(strcmp(my_mailbox, "1") == 0){
76 XBT_INFO("Propositions changed : r=1, cs=0");
79 MSG_task_receive(&grant, my_mailbox);
80 const char *kind = MSG_task_get_name(grant);
82 if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
85 XBT_INFO("Propositions changed : r=0, cs=1");
88 MSG_task_destroy(grant);
92 XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);
96 release = MSG_task_create("release", 0, 1000, NULL);
97 MSG_task_send(release, "coordinator");
101 MSG_process_sleep(my_pid);
103 if(strcmp(my_mailbox, "1") == 0){
106 XBT_INFO("Propositions changed : r=0, cs=0");
114 int main(int argc, char *argv[])
117 MSG_init(&argc, argv);
119 MSG_config("model-check/property","promela_bugged1_liveness");
120 MC_automaton_new_propositional_symbol("r", &predR);
121 MC_automaton_new_propositional_symbol("cs", &predCS);
123 MSG_create_environment("../msg_platform.xml");
124 MSG_function_register("coordinator", coordinator);
125 MSG_function_register("client", client);
126 MSG_launch_application("deploy_bugged1_liveness.xml");