Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use Mailbox::get_unique<>(), and save a few delete.
[simgrid.git] / examples / s4u / comm-waituntil / s4u-comm-waituntil.cpp
index d887e37..30532c6 100644 (file)
@@ -31,7 +31,7 @@ static void sender(int argc, char** argv)
     std::string mboxName        = std::string("receiver-") + std::to_string(i % receivers_count);
     simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
     std::string msgName         = std::string("Message ") + std::to_string(i);
-    std::string* payload        = new std::string(msgName); // copy the data we send:
+    auto* payload               = new std::string(msgName); // copy the data we send:
 
     // 'msgName' is not a stable storage location
     XBT_INFO("Send '%s' to '%s'", msgName.c_str(), mboxName.c_str());
@@ -45,7 +45,7 @@ static void sender(int argc, char** argv)
   for (int i = 0; i < receivers_count; i++) {
     std::string mboxName        = std::string("receiver-") + std::to_string(i % receivers_count);
     simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name(mboxName);
-    std::string* payload        = new std::string("finalize"); // Make a copy of the data we will send
+    auto* payload               = new std::string("finalize"); // Make a copy of the data we will send
 
     simgrid::s4u::CommPtr comm = mbox->put_async(payload, 0);
     pending_comms.push_back(comm);
@@ -71,11 +71,10 @@ static void receiver(int argc, char** argv)
 
   XBT_INFO("Wait for my first message");
   for (bool cont = true; cont;) {
-    const std::string* received = static_cast<std::string*>(mbox->get());
+    auto received = mbox->get_unique<std::string>();
     XBT_INFO("I got a '%s'.", received->c_str());
     if (*received == "finalize")
       cont = false; // If it's a finalize message, we're done.
-    delete received;
   }
 }