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");
29 int coordinator(int argc, char *argv[])
33 msg_task_t task = NULL, answer = NULL;
37 for(i=0; i<(NB_REQUESTS * NB_CLIENTS); i++){
38 MSG_task_receive(&task, "coordinator");
39 const char *kind = MSG_task_get_name(task);
40 if (!strcmp(kind, "request")) {
41 char *req = MSG_task_get_data(task);
43 //XBT_INFO("CS already used.");
45 if(strcmp(req, "1") != 0){
46 //XBT_INFO("CS idle. Grant immediatly");
47 answer = MSG_task_create("grant", 0, 1000, NULL);
48 MSG_task_send(answer, req);
54 //XBT_INFO("CS release. resource now idle");
57 MSG_task_destroy(task);
65 int client(int argc, char *argv[])
67 int my_pid = MSG_process_get_PID(MSG_process_self());
69 char *my_mailbox = xbt_strdup(argv[1]);
70 msg_task_t grant = NULL, release = NULL;
74 for(i=0; i<NB_REQUESTS; i++){
76 //XBT_INFO("Ask the request");
77 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
79 if(strcmp(my_mailbox, "1") == 0){
82 //XBT_INFO("Propositions changed : r=1, cs=0");
85 MSG_task_receive(&grant, my_mailbox);
86 const char *kind = MSG_task_get_name(grant);
88 if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
91 //XBT_INFO("Propositions changed : r=0, cs=1");
94 MSG_task_destroy(grant);
98 //XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);
100 MSG_process_sleep(1);
102 release = MSG_task_create("release", 0, 1000, NULL);
103 MSG_task_send(release, "coordinator");
107 MSG_process_sleep(my_pid);
109 if(strcmp(my_mailbox, "1") == 0){
112 //XBT_INFO("Propositions changed : r=0, cs=0");
120 int main(int argc, char *argv[])
123 MSG_init(&argc, argv);
125 MSG_config("model-check/property","promela_bugged1_liveness");
126 MC_automaton_new_propositional_symbol("r", &predR);
127 MC_automaton_new_propositional_symbol("cs", &predCS);
129 MSG_create_environment("../msg_platform.xml");
130 MSG_function_register("coordinator", coordinator);
131 MSG_function_register("client", client);
132 MSG_launch_application("deploy_bugged1_liveness.xml");