1 /***************** Centralized Mutual Exclusion Algorithm *********************/
2 /* This example implements a centralized mutual exclusion algorithm. */
3 /* Bug : 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;
31 xbt_dynar_t requests = xbt_dynar_new(sizeof(char *), NULL);
34 MSG_task_receive(&task, "coordinator");
35 const char *kind = MSG_task_get_name(task);
36 if (!strcmp(kind, "request")) {
37 char *req = MSG_task_get_data(task);
39 XBT_INFO("CS already used. Queue the request.");
40 xbt_dynar_push(requests, &req);
42 if(strcmp(req, "1") != 0){
43 XBT_INFO("CS idle. Grant immediatly");
44 answer = MSG_task_create("grant", 0, 1000, NULL);
45 MSG_task_send(answer, req);
51 if (!xbt_dynar_is_empty(requests)) {
52 XBT_INFO("CS release. Grant to queued requests (queue size: %lu)", xbt_dynar_length(requests));
54 xbt_dynar_pop(requests, &req);
55 if(strcmp(req, "1") != 0){
56 MSG_task_send(MSG_task_create("grant", 0, 1000, NULL), req);
58 xbt_dynar_push(requests, &req);
62 XBT_INFO("CS release. resource now idle");
66 MSG_task_destroy(task);
74 int client(int argc, char *argv[])
76 int my_pid = MSG_process_get_PID(MSG_process_self());
78 char *my_mailbox = xbt_strdup(argv[1]);
79 msg_task_t grant = NULL, release = NULL;
82 XBT_INFO("Ask the request");
83 MSG_task_send(MSG_task_create("request", 0, 1000, my_mailbox), "coordinator");
85 if(strcmp(my_mailbox, "1") == 0){
88 XBT_INFO("Propositions changed : r=1, cs=0");
91 MSG_task_receive(&grant, my_mailbox);
92 const char *kind = MSG_task_get_name(grant);
94 if((strcmp(my_mailbox, "1") == 0) && (strcmp("grant", kind) == 0)){
97 XBT_INFO("Propositions changed : r=0, cs=1");
100 MSG_task_destroy(grant);
104 XBT_INFO("%s got the answer. Sleep a bit and release it", argv[1]);
106 MSG_process_sleep(1);
108 release = MSG_task_create("release", 0, 1000, NULL);
109 MSG_task_send(release, "coordinator");
113 MSG_process_sleep(my_pid);
115 if(strcmp(my_mailbox, "1") == 0){
118 XBT_INFO("Propositions changed : r=0, cs=0");
126 int main(int argc, char *argv[])
129 MSG_init(&argc, argv);
131 char **options = &argv[1];
133 MSG_config("model-check/property","promela_bugged1_liveness");
134 MC_automaton_new_propositional_symbol("r", &predR);
135 MC_automaton_new_propositional_symbol("cs", &predCS);
137 const char* platform_file = options[0];
138 const char* application_file = options[1];
140 MSG_create_environment(platform_file);
141 MSG_function_register("coordinator", coordinator);
142 MSG_function_register("client", client);
143 MSG_launch_application(application_file);