Logo AND Algorithmique Numérique Distribuée

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