X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/21fe278c8460849931b37ccde22e944edec46f71..7915da3b4384df6fb6f40629e1ca8ebfe9157b48:/teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp diff --git a/teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp b/teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp index b7a4de5481..fac647598b 100644 --- a/teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp +++ b/teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2019. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2019-2020. 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. */ @@ -18,7 +18,7 @@ const int nb_sender = 100; int nb_messages_sent = 0; -simgrid::s4u::Mailbox* box; +simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test"); static void test_send(){ for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) { @@ -33,8 +33,10 @@ static void test_send(){ static void test_receive(){ for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) { XBT_VERB("waiting for messages"); - int id = *(int*)(box->get()); + int* ptr = (int*)(box->get()); + int id = *ptr; XBT_VERB("received messages #%i", id); + delete ptr; } XBT_INFO("Done receiving from %d senders, each of them sending %d messages", nb_sender, nb_message_to_send); } @@ -46,13 +48,11 @@ int main(int argc, char *argv[]) e.load_platform(argv[1]); - simgrid::s4u::ActorPtr receiver = simgrid::s4u::Actor::create("receiver", e.get_all_hosts()[0], test_receive); - for (int i = 0; i < nb_sender; i++) - simgrid::s4u::Actor::create("sender_" + std::to_string(i), e.get_all_hosts()[i % (e.get_host_count() - 1) + 1], - test_send); + auto hosts = e.get_all_hosts(); - box = simgrid::s4u::Mailbox::by_name("test"); - box->set_receiver(receiver); + simgrid::s4u::Actor::create("receiver", hosts[0], test_receive); + for (int i = 0; i < nb_sender; i++) + simgrid::s4u::Actor::create("sender_" + std::to_string(i), hosts[i % (e.get_host_count() - 1) + 1], test_send); e.run();