1 /* Copyright (c) 2010-2023. 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(mc_assert_example, "Logging channel used in this example");
15 namespace sg4 = simgrid::s4u;
17 static int server(int worker_amount)
20 sg4::Mailbox* mb = sg4::Mailbox::by_name("server");
21 for (int count = 0; count < worker_amount; count++) {
22 auto msg = mb->get_unique<int>();
26 * We assert here that the last message we got (which overwrite any previously received message) is the one from the
27 * last worker This will obviously fail when the messages are received out of order.
29 MC_assert(value_got == 2);
35 static int client(int rank)
37 /* I just send my rank onto the mailbox. It must be passed as a stable memory block (thus the new) so that that
38 * memory survives even after the end of the client */
40 sg4::Mailbox* mailbox = sg4::Mailbox::by_name("server");
41 mailbox->put(new int(rank), 1 /* communication cost is not really relevant in MC mode */);
47 int main(int argc, char* argv[])
49 sg4::Engine e(&argc, argv);
50 xbt_assert(argc > 1, "Usage: %s platform_file\n", argv[0]);
52 e.load_platform(argv[1]);
53 auto hosts = e.get_all_hosts();
54 xbt_assert(hosts.size() >= 3, "This example requires at least 3 hosts");
56 sg4::Actor::create("server", hosts[0], &server, 2);
57 sg4::Actor::create("client1", hosts[1], &client, 1);
58 sg4::Actor::create("client2", hosts[2], &client, 2);