Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into mc-process
[simgrid.git] / examples / msg / mc / bugged3.c
1 /* Copyright (c) 2010-2014. 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 /**************** Shared buffer between asynchronous receives *****************/
8 /* Server process assumes that the data from the second communication comm2   */
9 /* will overwrite the one from the first communication, because of the order  */
10 /* of the wait calls. This is not true because data copy can be triggered by  */
11 /* a call to wait on the other end of the communication (client).             */
12 /* NOTE that the communications use different mailboxes, but they share the   */
13 /* same buffer for reception (task1).                                         */
14 /******************************************************************************/
15
16 #include <simgrid/msg.h>
17 #include <simgrid/modelchecker.h>
18
19 XBT_LOG_NEW_DEFAULT_CATEGORY(bugged3, "this example");
20
21 int server(int argc, char *argv[]);
22 int client(int argc, char *argv[]);
23
24 int server(int argc, char *argv[])
25 {
26   msg_task_t task1;
27   long val1;
28   msg_comm_t comm1, comm2;
29
30   comm1 = MSG_task_irecv(&task1, "mymailbox1");
31   comm2 = MSG_task_irecv(&task1, "mymailbox2");
32   MSG_comm_wait(comm1, -1);
33   MSG_comm_wait(comm2, -1);
34
35   val1 = (long) MSG_task_get_data(task1);
36   XBT_INFO("Received %lu", val1);
37
38   MC_assert(val1 == 2);
39
40   XBT_INFO("OK");
41   return 0;
42 }
43
44 int client(int argc, char *argv[])
45 {
46   msg_comm_t comm;
47   char *mbox;
48   msg_task_t task1 =
49       MSG_task_create("task", 0, 10000, (void *) atol(argv[1]));
50
51   mbox = bprintf("mymailbox%s", argv[1]);
52
53   XBT_INFO("Send %d!", atoi(argv[1]));
54   comm = MSG_task_isend(task1, mbox);
55   MSG_comm_wait(comm, -1);
56
57   xbt_free(mbox);
58
59   return 0;
60 }
61
62 int main(int argc, char *argv[])
63 {
64   MSG_init(&argc, argv);
65
66   MSG_create_environment("platform.xml");
67
68   MSG_function_register("server", server);
69
70   MSG_function_register("client", client);
71
72   MSG_launch_application("deploy_bugged3.xml");
73
74   MSG_main();
75
76   return 0;
77 }