Logo AND Algorithmique Numérique Distribuée

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