Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
factor Cmake and clean files
[simgrid.git] / examples / msg / mc / bugged2.c
1 /* Copyright (c) 2010-2015. 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 <simgrid/msg.h>
13 #include <simgrid/modelchecker.h>
14 #define N 3
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
17
18 static int server(int argc, char *argv[])
19 {
20   msg_task_t task1 = NULL;
21   msg_task_t task2 = NULL;
22   long val1, val2;
23
24   MSG_task_receive(&task1, "mymailbox");
25   val1 = xbt_str_parse_int(MSG_task_get_name(task1), "Task name is not a numerical ID: %s");
26   MSG_task_destroy(task1);
27   task1 = NULL;
28   XBT_INFO("Received %lu", val1);
29
30   MSG_task_receive(&task2, "mymailbox");
31   val2 = xbt_str_parse_int(MSG_task_get_name(task2), "Task name is not a numerical ID: %s");
32   MSG_task_destroy(task2);
33   task2 = NULL;
34   XBT_INFO("Received %lu", val2);
35
36   MC_assert(MIN(val1, val2) == 1);
37
38   MSG_task_receive(&task1, "mymailbox");
39   val1 = xbt_str_parse_int(MSG_task_get_name(task1), "Task name is not a numerical ID: %s");
40   MSG_task_destroy(task1);
41   XBT_INFO("Received %lu", val1);
42
43   MSG_task_receive(&task2, "mymailbox");
44   val2 = xbt_str_parse_int(MSG_task_get_name(task2), "Task name is not a numerical ID: %s");
45   MSG_task_destroy(task2);
46   XBT_INFO("Received %lu", val2);
47
48   XBT_INFO("OK");
49   return 0;
50 }
51
52 static int client(int argc, char *argv[])
53 {
54   msg_task_t task1 = MSG_task_create(argv[1], 0, 10000, NULL);
55   msg_task_t task2 = MSG_task_create(argv[1], 0, 10000, NULL);
56
57   XBT_INFO("Send %s", argv[1]);
58   MSG_task_send(task1, "mymailbox");
59
60   XBT_INFO("Send %s", argv[1]);
61   MSG_task_send(task2, "mymailbox");
62
63   return 0;
64 }
65
66 int main(int argc, char *argv[])
67 {
68   MSG_init(&argc, argv);
69
70   MSG_create_environment("platform.xml");
71
72   MSG_function_register("server", server);
73   MSG_function_register("client", client);
74   MSG_launch_application("deploy_bugged2.xml");
75
76   MSG_main();
77   return 0;
78 }