1 /* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. */
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. */
6 /******************** Non-deterministic message ordering *********************/
7 /* Server assumes a fixed order in the reception of messages from its clients */
8 /* which is incorrect because the message ordering is non-deterministic */
9 /******************************************************************************/
11 #include <simgrid/modelchecker.h>
12 #include <simgrid/s4u.hpp>
14 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
15 namespace sg4 = simgrid::s4u;
19 auto received1 = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
20 long val1 = *received1;
22 auto received2 = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
23 long val2 = *received2;
25 XBT_INFO("First pair received: %ld %ld", val1, val2);
27 MC_assert(std::min(val1, val2) == 1); // if the two messages of the second client arrive first, this is violated.
29 received1 = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
32 received2 = sg4::Mailbox::by_name("mymailbox")->get_unique<int>();
35 XBT_INFO("Second pair received: %ld %ld", val1, val2);
38 static void client(int id)
40 auto* payload1 = new int(id);
41 auto* payload2 = new int(id);
43 sg4::Mailbox::by_name("mymailbox")->put(payload1, 10000);
44 sg4::Mailbox::by_name("mymailbox")->put(payload2, 10000);
47 int main(int argc, char* argv[])
49 sg4::Engine e(&argc, argv);
51 e.load_platform(argv[1]);
53 sg4::Actor::create("server", e.host_by_name("HostA"), server);
54 sg4::Actor::create("client", e.host_by_name("HostB"), client, 1);
55 sg4::Actor::create("client", e.host_by_name("HostC"), client, 2);