1 /* Copyright (c) 2009-2021. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #include "simgrid/s4u.hpp"
9 XBT_LOG_NEW_DEFAULT_CATEGORY(test, "Messages specific to this example");
11 static void sender_fun()
14 auto* payload = new std::string("Blah");
15 simgrid::s4u::Mailbox::by_name("Tremblay")->put(payload, 0);
16 simgrid::s4u::this_actor::sleep_for(1.0);
20 static void receiver_fun()
22 XBT_INFO("Receiving");
23 std::string* payload = nullptr;
24 simgrid::s4u::CommPtr comm = simgrid::s4u::Mailbox::by_name("Tremblay")->get_async<std::string>(&payload);
26 xbt_assert(comm->get_sender(), "No sender received");
27 XBT_INFO("Got a message sent by '%s'", comm->get_sender()->get_cname());
28 simgrid::s4u::this_actor::sleep_for(2.0);
29 XBT_INFO("Did I tell you that I got a message sent by '%s'?", comm->get_sender()->get_cname());
33 int main(int argc, char* argv[])
35 simgrid::s4u::Engine e(&argc, argv);
37 e.load_platform(argv[1]);
39 simgrid::s4u::Actor::create("send", e.host_by_name("Tremblay"), sender_fun);
40 simgrid::s4u::Actor::create("receive", e.host_by_name("Tremblay"), receiver_fun);