Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / mc-bugged2 / s4u-mc-bugged2.cpp
1 /* Copyright (c) 2010-2021. 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   received1 = nullptr;
24   XBT_INFO("Received %ld", val1);
25
26   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
27   long val2 = *received2;
28   received2 = nullptr;
29   XBT_INFO("Received %ld", val2);
30
31   MC_assert(std::min(val1, val2) == 1);
32
33   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
34   val1      = *received1;
35   XBT_INFO("Received %ld", val1);
36
37   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
38   val2      = *received2;
39   XBT_INFO("Received %ld", val2);
40
41   XBT_INFO("OK");
42 }
43
44 static void client(int id)
45 {
46   auto* payload1 = new int(id);
47   auto* payload2 = new int(id);
48
49   XBT_INFO("Send %d", id);
50   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload1, 10000);
51
52   XBT_INFO("Send %d", id);
53   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload2, 10000);
54 }
55
56 int main(int argc, char* argv[])
57 {
58   simgrid::s4u::Engine e(&argc, argv);
59
60   e.load_platform(argv[1]);
61
62   simgrid::s4u::Actor::create("server", simgrid::s4u::Host::by_name("HostA"), server);
63   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostB"), client, 1);
64   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostC"), client, 2);
65
66   e.run();
67   return 0;
68 }