Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / examples / cpp / mc-electric-fence / s4u-mc-electric-fence.cpp
1 /* Copyright (c) 2013-2022. 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 actor which receives messages from two other   */
8 /* actors. 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 namespace sg4 = simgrid::s4u;
19
20 static void server()
21 {
22   int* data1                  = nullptr;
23   int* data2                  = nullptr;
24   sg4::CommPtr comm_received1 = sg4::Mailbox::by_name("mymailbox")->get_async<int>(&data1);
25   sg4::CommPtr comm_received2 = sg4::Mailbox::by_name("mymailbox")->get_async<int>(&data2);
26
27   comm_received1->wait();
28   comm_received2->wait();
29
30   XBT_INFO("OK");
31   delete data1;
32   delete data2;
33 }
34
35 static void client(int id)
36 {
37   auto* payload = new int(id);
38   sg4::Mailbox::by_name("mymailbox")->put(payload, 10000);
39   XBT_INFO("Sent!");
40 }
41
42 int main(int argc, char* argv[])
43 {
44   sg4::Engine e(&argc, argv);
45
46   e.load_platform(argv[1]);
47
48   sg4::Actor::create("server", e.host_by_name("HostA"), server);
49   sg4::Actor::create("client", e.host_by_name("HostB"), client, 1);
50   sg4::Actor::create("client", e.host_by_name("HostC"), client, 2);
51
52   e.run();
53   return 0;
54 }