1 /* Copyright (c) 2019-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. */
8 #include <simgrid/s4u.hpp>
11 XBT_LOG_NEW_DEFAULT_CATEGORY(meh, "meh");
15 auto mbox = simgrid::s4u::Mailbox::by_name("meh");
19 XBT_INFO("Sending and receiving %d and %d asynchronously", input1, input2);
21 auto put1 = mbox->put_async(&input1, 1000 * 1000 * 500);
22 auto put2 = mbox->put_async(&input2, 1000 * 1000 * 1000);
25 auto get1 = mbox->get_async<int>(&out1);
28 auto get2 = mbox->get_async<int>(&out2);
30 XBT_INFO("All comms have started");
31 std::vector<simgrid::s4u::CommPtr> comms = {put1, put2, get1, get2};
33 while (not comms.empty()) {
34 size_t index = simgrid::s4u::Comm::wait_all_for(comms, 0.5);
35 if (index < comms.size())
36 XBT_INFO("wait_all_for: Timeout reached");
37 XBT_INFO("wait_all_for: %zu comms finished (#comms=%zu)", index, comms.size());
38 comms.erase(comms.begin(), comms.begin() + index);
41 XBT_INFO("All comms have finished");
42 XBT_INFO("Got %d and %d", *out1, *out2);
45 int main(int argc, char* argv[])
48 simgrid::s4u::Engine e(&argc, argv);
49 e.load_platform(argv[1]);
50 simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), worker);