X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/792d345c65ef01853c9f0b32015ee7e28fdf4ea7..5ed37babb2fa9097abe82df299c0aa259ed84d5a:/examples/cpp/comm-waitall/s4u-comm-waitall.cpp diff --git a/examples/cpp/comm-waitall/s4u-comm-waitall.cpp b/examples/cpp/comm-waitall/s4u-comm-waitall.cpp index 8c5d2e51de..5c3f863626 100644 --- a/examples/cpp/comm-waitall/s4u-comm-waitall.cpp +++ b/examples/cpp/comm-waitall/s4u-comm-waitall.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2023. 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. */ @@ -22,6 +22,10 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_async_waitall, "Messages specific for this s4u static void sender(unsigned int messages_count, unsigned int receivers_count, long msg_size) { + if (messages_count == 0 || receivers_count == 0) { + XBT_WARN("Sender has nothing to do. Bail out!"); + return; + } // sphinx-doc: init-begin (this line helps the doc to build; ignore it) /* Vector in which we store all ongoing communications */ std::vector pending_comms; @@ -29,12 +33,12 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Make a vector of the mailboxes to use */ std::vector mboxes; for (unsigned int i = 0; i < receivers_count; i++) - mboxes.push_back(sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(i))); + mboxes.push_back(sg4::Mailbox::by_name("receiver-" + std::to_string(i))); // sphinx-doc: init-end /* Start dispatching all messages to receivers, in a round robin fashion */ for (unsigned int i = 0; i < messages_count; i++) { - std::string msg_content = std::string("Message ") + std::to_string(i); + std::string msg_content = "Message " + std::to_string(i); // Copy the data we send: the 'msg_content' variable is not a stable storage location. // It will be destroyed when this actor leaves the loop, ie before the receiver gets it auto* payload = new std::string(msg_content); @@ -64,7 +68,7 @@ static void sender(unsigned int messages_count, unsigned int receivers_count, lo /* Receiver actor expects 1 argument: its ID */ static void receiver(int id) { - sg4::Mailbox* mbox = sg4::Mailbox::by_name(std::string("receiver-") + std::to_string(id)); + sg4::Mailbox* mbox = sg4::Mailbox::by_name("receiver-" + std::to_string(id)); XBT_INFO("Wait for my first message"); for (bool cont = true; cont;) { auto received = mbox->get_unique();