Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : bugged2_liveness with promela of LTL properties checked
[simgrid.git] / examples / msg / mc / bugged2.c
1 /******************** Non-deterministic message ordering  *********************/
2 /* Server assumes a fixed order in the reception of messages from its clients */
3 /* which is incorrect because the message ordering is non-deterministic       */
4 /******************************************************************************/
5
6 #include <msg/msg.h>
7 #include <mc/modelchecker.h>
8 #define N 3
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
11
12 int server(int argc, char *argv[]);
13 int client(int argc, char *argv[]);
14
15 int server(int argc, char *argv[])
16 {
17   m_task_t task1 = NULL;
18   m_task_t task2 = NULL;
19   long val1, val2;
20
21   MSG_task_receive(&task1, "mymailbox");
22   val1 = (long) MSG_task_get_data(task1);
23   MSG_task_destroy(task1);
24   task1 = NULL;
25   XBT_INFO("Received %lu", val1);
26
27   MSG_task_receive(&task2, "mymailbox");
28   val2 = (long) MSG_task_get_data(task2);
29   MSG_task_destroy(task2);
30   task2 = NULL;
31   XBT_INFO("Received %lu", val2);
32
33   MC_assert(min(val1, val2) == 1);
34
35   MSG_task_receive(&task1, "mymailbox");
36   val1 = (long) MSG_task_get_data(task1);
37   MSG_task_destroy(task1);
38   XBT_INFO("Received %lu", val1);
39
40   MSG_task_receive(&task2, "mymailbox");
41   val2 = (long) MSG_task_get_data(task2);
42   MSG_task_destroy(task2);
43   XBT_INFO("Received %lu", val2);
44
45   XBT_INFO("OK");
46   return 0;
47 }
48
49 int client(int argc, char *argv[])
50 {
51   m_task_t task1 =
52       MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
53   m_task_t task2 =
54       MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
55
56   XBT_INFO("Send %d!", atoi(argv[1]));
57   MSG_task_send(task1, "mymailbox");
58
59   XBT_INFO("Send %d!", atoi(argv[1]));
60   MSG_task_send(task2, "mymailbox");
61
62   return 0;
63 }
64
65 int main(int argc, char *argv[])
66 {
67   MSG_global_init(&argc, argv);
68
69   MSG_create_environment("platform.xml");
70
71   MSG_function_register("server", server);
72
73   MSG_function_register("client", client);
74
75   MSG_launch_application("deploy_bugged2.xml");
76
77   MSG_main();
78
79   return 0;
80 }