Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
spelling mistakes in include/ and examples/
[simgrid.git] / examples / s4u / mc-bugged2 / s4u-mc-bugged2.cpp
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 /******************** 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   void* received1 = nullptr;
19   void* received2 = nullptr;
20
21   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
22   long val1 = *(static_cast<int*>(received1));
23   received1 = nullptr;
24   XBT_INFO("Received %ld", val1);
25
26   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
27   long val2 = *(static_cast<int*>(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();
34   val1      = *(static_cast<int*>(received1));
35   XBT_INFO("Received %ld", val1);
36
37   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
38   val2      = *(static_cast<int*>(received2));
39   XBT_INFO("Received %ld", val2);
40
41   XBT_INFO("OK");
42 }
43
44 static void client(int id)
45 {
46   int* payload1 = new int();
47   *payload1     = id;
48   int* payload2 = new int();
49   *payload2     = id;
50
51   XBT_INFO("Send %d", id);
52   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload1, 10000);
53
54   XBT_INFO("Send %d", id);
55   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload2, 10000);
56 }
57
58 int main(int argc, char* argv[])
59 {
60   simgrid::s4u::Engine e(&argc, argv);
61
62   e.load_platform(argv[1]);
63
64   simgrid::s4u::Actor::create("server", simgrid::s4u::Host::by_name("HostA"), server);
65   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostB"), client, 1);
66   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostC"), client, 2);
67
68   e.run();
69   return 0;
70 }