Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the depends of iSend/iRecv vs. WaitComm to fix the bugged2 example
[simgrid.git] / examples / cpp / mc-bugged2 / s4u-mc-bugged2.cpp
1 /* Copyright (c) 2010-2022. 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/modelchecker.h>
12 #include <simgrid/s4u.hpp>
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
15
16 static void server()
17 {
18   const int* received1 = nullptr;
19   const int* received2 = nullptr;
20
21   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
22   long val1 = *received1;
23   delete received1;
24
25   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
26   long val2 = *received2;
27   delete received2;
28
29   XBT_INFO("First pair received: %ld %ld", val1, val2);
30
31   MC_assert(std::min(val1, val2) == 1); // if the two messages of the second client arrive first, this is violated.
32
33   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
34   val1      = *received1;
35   delete received1;
36
37   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
38   val2      = *received2;
39   delete received2;
40
41   XBT_INFO("Second pair received: %ld %ld", val1, val2);
42 }
43
44 static void client(int id)
45 {
46   auto* payload1 = new int(id);
47   auto* payload2 = new int(id);
48
49   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload1, 10000);
50   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload2, 10000);
51 }
52
53 int main(int argc, char* argv[])
54 {
55   simgrid::s4u::Engine e(&argc, argv);
56
57   e.load_platform(argv[1]);
58
59   simgrid::s4u::Actor::create("server", e.host_by_name("HostA"), server);
60   simgrid::s4u::Actor::create("client", e.host_by_name("HostB"), client, 1);
61   simgrid::s4u::Actor::create("client", e.host_by_name("HostC"), client, 2);
62
63   e.run();
64   return 0;
65 }