Logo AND Algorithmique Numérique Distribuée

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