Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[mc] Fix context registration which was disabled by a bug
[simgrid.git] / examples / msg / mc / bugged3.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 /**************** 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,task2;
27
28   msg_comm_t comm1 = MSG_task_irecv(&task1, "mymailbox1");
29   msg_comm_t comm2 = MSG_task_irecv(&task2, "mymailbox2");
30   MSG_comm_wait(comm1, -1);
31   MSG_comm_wait(comm2, -1);
32
33   long val1 = xbt_str_parse_int(MSG_task_get_name(task1), "Task name is not a numerical ID: %s");
34   XBT_INFO("Received %lu", val1);
35
36   MC_assert(val1 == 2);
37
38   XBT_INFO("OK");
39   return 0;
40 }
41
42 int client(int argc, char *argv[])
43 {
44   msg_task_t task1 = MSG_task_create(argv[1], 0, 10000, NULL);
45
46   char *mbox = bprintf("mymailbox%s", argv[1]);
47
48   XBT_INFO("Send %s!", argv[1]);
49   msg_comm_t comm = MSG_task_isend(task1, mbox);
50   MSG_comm_wait(comm, -1);
51
52   xbt_free(mbox);
53
54   return 0;
55 }
56
57 int main(int argc, char *argv[])
58 {
59   MSG_init(&argc, argv);
60
61   MSG_create_environment("platform.xml");
62
63   MSG_function_register("server", server);
64   MSG_function_register("client", client);
65   MSG_launch_application("deploy_bugged3.xml");
66
67   MSG_main();
68
69   return 0;
70 }