Logo AND Algorithmique Numérique Distribuée

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