Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #179 from Takishipp/signals
[simgrid.git] / examples / msg / mc / bugged1.c
1 /* Copyright (c) 2010-2017. 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
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 task = NULL;
21   int count = 0;
22   while (count < N) {
23     if (task) {
24       MSG_task_destroy(task);
25       task = NULL;
26     }
27     MSG_task_receive(&task, "mymailbox");
28     count++;
29   }
30   int value_got = xbt_str_parse_int(MSG_task_get_name(task), "Task names must be integers, not '%s'");
31   MC_assert(value_got == 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 }