1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/* Copyright (c) 2010-2025. The SimGrid Team. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/******************** Non-deterministic message ordering *********************/
/* Server assumes a fixed order in the reception of messages from its clients */
/* which is incorrect because the message ordering is non-deterministic */
/******************************************************************************/
#include <simgrid/modelchecker.h>
#include <simgrid/s4u.hpp>
constexpr int N = 3;
XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
namespace sg4 = simgrid::s4u;
static void server()
{
std::unique_ptr<int> received;
int count = 0;
while (count < N) {
received.reset();
received = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
count++;
}
int value_got = *received;
MC_assert(value_got == 3);
XBT_INFO("OK");
}
static void client(int id)
{
auto* payload = new int(id);
sg4::Mailbox::by_name("mymailbox")->put(payload, 10000);
XBT_INFO("Sent!");
}
int main(int argc, char* argv[])
{
sg4::Engine e(&argc, argv);
e.load_platform(argv[1]);
e.add_actor("server", e.host_by_name("HostA"), server);
e.add_actor("client", e.host_by_name("HostB"), client, 1);
e.add_actor("client", e.host_by_name("HostC"), client, 2);
e.add_actor("client", e.host_by_name("HostD"), client, 3);
e.run();
return 0;
}
|