Logo AND Algorithmique Numérique Distribuée

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