Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'coverity_scan' of github.com:mquinson/simgrid
[simgrid.git] / examples / msg / mc / bugged1.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
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 task = NULL;
25   int count = 0;
26   while (count < N) {
27     if (task) {
28       MSG_task_destroy(task);
29       task = NULL;
30     }
31     MSG_task_receive(&task, "mymailbox");
32     count++;
33   }
34   MC_assert(xbt_str_parse_int(MSG_task_get_name(task), "Task names must be integers, not '%s'") == 3);
35
36   XBT_INFO("OK");
37   return 0;
38 }
39
40 int client(int argc, char *argv[])
41 {
42
43   msg_task_t task =
44       MSG_task_create(argv[1], 0 /*comp cost */ , 10000 /*comm size */ ,
45                       NULL /*arbitrary data */ );
46
47   MSG_task_send(task, "mymailbox");
48
49   XBT_INFO("Sent!");
50   return 0;
51 }
52
53 int main(int argc, char *argv[])
54 {
55
56   MSG_init(&argc, argv);
57
58   MSG_create_environment("platform.xml");
59
60   MSG_function_register("server", server);
61
62   MSG_function_register("client", client);
63
64   MSG_launch_application("deploy_bugged1.xml");
65
66   MSG_main();
67
68   return 0;
69
70 }