Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
convert mc-bugged1 and mc-bugged2
[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 #define N 3
14
15 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
16
17 static void server()
18 {
19   void* received1 = nullptr;
20   void* received2 = nullptr;
21
22   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
23   long val1 = *(static_cast<int*>(received1));
24   received1 = nullptr;
25   XBT_INFO("Received %ld", val1);
26
27   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
28   long val2 = *(static_cast<int*>(received2));
29   received2 = nullptr;
30   XBT_INFO("Received %ld", val2);
31
32   MC_assert(std::min(val1, val2) == 1);
33
34   received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
35   val1      = *(static_cast<int*>(received1));
36   XBT_INFO("Received %ld", val1);
37
38   received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get();
39   val2      = *(static_cast<int*>(received2));
40   XBT_INFO("Received %ld", val2);
41
42   XBT_INFO("OK");
43 }
44
45 static void client(int id)
46 {
47   int* payload1 = new int();
48   *payload1     = id;
49   int* payload2 = new int();
50   *payload2     = id;
51
52   XBT_INFO("Send %d", id);
53   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload1, 10000);
54
55   XBT_INFO("Send %d", id);
56   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload2, 10000);
57 }
58
59 int main(int argc, char* argv[])
60 {
61   simgrid::s4u::Engine e(&argc, argv);
62
63   e.load_platform(argv[1]);
64
65   simgrid::s4u::Actor::create("server", simgrid::s4u::Host::by_name("HostA"), server);
66   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostB"), client, 1);
67   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostC"), client, 2);
68
69   e.run();
70   return 0;
71 }