Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Another attempt at fixing the Flag2 job of jenkins
[simgrid.git] / examples / cpp / mc-bugged1 / s4u-mc-bugged1.cpp
1 /* Copyright (c) 2010-2023. 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 constexpr int N = 3;
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
17 namespace sg4 = simgrid::s4u;
18
19 static void server()
20 {
21   std::unique_ptr<int> received;
22   int count     = 0;
23   while (count < N) {
24     received.reset();
25     received = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
26     count++;
27   }
28   int value_got = *received;
29   MC_assert(value_got == 3);
30
31   XBT_INFO("OK");
32 }
33
34 static void client(int id)
35 {
36   auto* payload = new int(id);
37   sg4::Mailbox::by_name("mymailbox")->put(payload, 10000);
38
39   XBT_INFO("Sent!");
40 }
41
42 int main(int argc, char* argv[])
43 {
44   sg4::Engine e(&argc, argv);
45
46   e.load_platform(argv[1]);
47
48   sg4::Actor::create("server", e.host_by_name("HostA"), server);
49   sg4::Actor::create("client", e.host_by_name("HostB"), client, 1);
50   sg4::Actor::create("client", e.host_by_name("HostC"), client, 2);
51   sg4::Actor::create("client", e.host_by_name("HostD"), client, 3);
52
53   e.run();
54   return 0;
55 }