Logo AND Algorithmique Numérique Distribuée

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