Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
c90257ac9ad0e58f1956248e427b281a02c36547
[simgrid.git] / examples / msg / mc / bugged1.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 <simgrid/modelchecker.h>
8
9 #define N 3
10
11 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
12
13 int server(int argc, char *argv[]);
14 int client(int argc, char *argv[]);
15
16 int server(int argc, char *argv[])
17 {
18   msg_task_t task = NULL;
19   int count = 0;
20   while (count < N) {
21     if (task) {
22       MSG_task_destroy(task);
23       task = NULL;
24     }
25     MSG_task_receive(&task, "mymailbox");
26     count++;
27   }
28   MC_assert(atoi(MSG_task_get_name(task)) == 3);
29
30   XBT_INFO("OK");
31   return 0;
32 }
33
34 int client(int argc, char *argv[])
35 {
36
37   msg_task_t task =
38       MSG_task_create(argv[1], 0 /*comp cost */ , 10000 /*comm size */ ,
39                       NULL /*arbitrary data */ );
40
41   MSG_task_send(task, "mymailbox");
42
43   XBT_INFO("Sent!");
44   return 0;
45 }
46
47 int main(int argc, char *argv[])
48 {
49
50   MSG_init(&argc, argv);
51
52   MSG_create_environment("platform.xml");
53
54   MSG_function_register("server", server);
55
56   MSG_function_register("client", client);
57
58   MSG_launch_application("deploy_bugged1.xml");
59
60   MSG_main();
61
62   MSG_clean();
63
64   return 0;
65
66 }