Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / examples / s4u / mc-electric-fence / s4u-mc-electric-fence.cpp
1 /* Copyright (c) 2013-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 /* 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   int* data1                           = nullptr;
21   int* data2                           = nullptr;
22   simgrid::s4u::CommPtr comm_received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async<int>(&data1);
23   simgrid::s4u::CommPtr comm_received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async<int>(&data2);
24
25   comm_received1->wait();
26   comm_received2->wait();
27
28   XBT_INFO("OK");
29   delete data1;
30   delete data2;
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   XBT_INFO("Sent!");
38 }
39
40 int main(int argc, char* argv[])
41 {
42   simgrid::s4u::Engine e(&argc, argv);
43
44   e.load_platform(argv[1]);
45
46   simgrid::s4u::Actor::create("server", simgrid::s4u::Host::by_name("HostA"), server);
47   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostB"), client, 1);
48   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostC"), client, 2);
49
50   e.run();
51   return 0;
52 }