Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
0dbced13561fd0bf27a63c95f3fbef1bea2e685c
[simgrid.git] / examples / s4u / mc-electric-fence / s4u-mc-electric-fence.cpp
1 /* Copyright (c) 2013-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 /* This example implements one process which receives messages from two other */
8 /* processes. There is no bug on it, it is just provided to test the soundness*/
9 /* of the state space reduction with DPOR, if the maximum depth (defined with */
10 /* --cfg=model-check/max-depth:) is reached.                                  */
11 /******************************************************************************/
12
13 #include <simgrid/modelchecker.h>
14 #include <simgrid/s4u.hpp>
15
16 XBT_LOG_NEW_DEFAULT_CATEGORY(electric_fence, "Example to check the soundness of DPOR");
17
18 static void server()
19 {
20   void* data1                          = nullptr;
21   void* data2                          = nullptr;
22   simgrid::s4u::CommPtr comm_received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async(&data1);
23   simgrid::s4u::CommPtr comm_received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async(&data2);
24
25   comm_received1->wait();
26   comm_received2->wait();
27
28   XBT_INFO("OK");
29   delete static_cast<int*>(data1);
30   delete static_cast<int*>(data2);
31 }
32
33 static void client(int id)
34 {
35   int* payload = new int();
36   *payload     = id;
37   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000);
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("platform.xml");
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
51   e.run();
52   return 0;
53 }