Logo AND Algorithmique Numérique Distribuée

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