Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
dbeeaa1cf9c47352fef17afd9ed01c06790bfb25
[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 #define N 2
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(electric_fence, "Example to check the soundness of DPOR");
19
20 static void server()
21 {
22   void* data1                          = nullptr;
23   void* data2                          = nullptr;
24   simgrid::s4u::CommPtr comm_received1 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async(&data1);
25   simgrid::s4u::CommPtr comm_received2 = simgrid::s4u::Mailbox::by_name("mymailbox")->get_async(&data2);
26
27   comm_received1->wait();
28   comm_received2->wait();
29
30   XBT_INFO("OK");
31   delete static_cast<int*>(data1);
32   delete static_cast<int*>(data2);
33 }
34
35 static void client(int id)
36 {
37   int* payload = new int();
38   *payload     = id;
39   simgrid::s4u::Mailbox::by_name("mymailbox")->put(payload, 10000);
40   XBT_INFO("Sent!");
41 }
42
43 int main(int argc, char* argv[])
44 {
45   simgrid::s4u::Engine e(&argc, argv);
46
47   e.load_platform("platform.xml");
48
49   simgrid::s4u::Actor::create("server", simgrid::s4u::Host::by_name("HostA"), server);
50   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostB"), client, 1);
51   simgrid::s4u::Actor::create("client", simgrid::s4u::Host::by_name("HostC"), client, 2);
52
53   e.run();
54   return 0;
55 }