Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use Mailbox::get_unique<>(), and save a few delete.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 13:15:31 +0000 (14:15 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 17 Dec 2020 13:17:38 +0000 (14:17 +0100)
35 files changed:
docs/source/tuto_s4u/master-workers-lab1.cpp
docs/source/tuto_s4u/master-workers-lab2.cpp
docs/source/tuto_s4u/master-workers-lab3.cpp
docs/source/tuto_s4u/master-workers-lab4.cpp
examples/s4u/actor-create/s4u-actor-create.cpp
examples/s4u/app-bittorrent/s4u-peer.cpp
examples/s4u/app-chainsend/s4u-app-chainsend.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-class.cpp
examples/s4u/app-masterworkers/s4u-app-masterworkers-fun.cpp
examples/s4u/app-pingpong/s4u-app-pingpong.cpp
examples/s4u/cloud-simple/s4u-cloud-simple.cpp
examples/s4u/comm-ready/s4u-comm-ready.cpp
examples/s4u/comm-suspend/s4u-comm-suspend.cpp
examples/s4u/comm-waitall/s4u-comm-waitall.cpp
examples/s4u/comm-waitany/s4u-comm-waitany.cpp
examples/s4u/comm-waituntil/s4u-comm-waituntil.cpp
examples/s4u/maestro-set/s4u-maestro-set.cpp
examples/s4u/mc-bugged1-liveness/s4u-mc-bugged1-liveness.cpp
examples/s4u/mc-bugged1/s4u-mc-bugged1.cpp
examples/s4u/mc-failing-assert/s4u-mc-failing-assert.cpp
examples/s4u/network-ns3/s4u-network-ns3.cpp
examples/s4u/platform-failures/s4u-platform-failures.cpp
examples/s4u/replay-comm/s4u-replay-comm.cpp
examples/s4u/trace-categories/s4u-trace-categories.cpp
examples/s4u/trace-masterworkers/s4u-trace-masterworkers.cpp
examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp
src/plugins/vm/VmLiveMigration.cpp
teshsuite/mc/mutex-handling/mutex-handling.cpp
teshsuite/s4u/host-on-off-actors/host-on-off-actors.cpp
teshsuite/s4u/host-on-off-recv/host-on-off-recv.cpp
teshsuite/s4u/host-on-off/host-on-off.cpp
teshsuite/s4u/listen_async/listen_async.cpp
teshsuite/s4u/ns3-from-src-to-itself/ns3-from-src-to-itself.cpp
teshsuite/s4u/ns3-simultaneous-send-rcv/ns3-simultaneous-send-rcv.cpp
teshsuite/s4u/storage_client_server/storage_client_server.cpp

index 12fcdda..2bf93a2 100644 (file)
@@ -58,9 +58,8 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    double* msg  = mailbox->get<double>();
+    auto msg     = mailbox->get_unique<double>();
     compute_cost = *msg;
-    delete msg;
 
     if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
       simgrid::s4u::this_actor::execute(compute_cost);
index df78adf..a87631b 100644 (file)
@@ -23,9 +23,8 @@ static void worker()
 
   double compute_cost;
   do {
-    double* msg  = mailbox->get<double>();
+    auto msg     = mailbox->get_unique<double>();
     compute_cost = *msg;
-    delete msg;
 
     if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
       simgrid::s4u::this_actor::execute(compute_cost);
index a2f3963..5e012ff 100644 (file)
@@ -22,9 +22,8 @@ static void worker()
   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(mailbox_name);
 
   while (true) { // Master forcefully kills the workers by the end of the simulation
-    double* msg         = mailbox->get<double>();
+    auto msg            = mailbox->get_unique<double>();
     double compute_cost = *msg;
-    delete msg;
 
     simgrid::s4u::this_actor::execute(compute_cost);
   }
index 7752e31..c2c8f4d 100644 (file)
@@ -22,9 +22,8 @@ static void worker(std::string category)
   simgrid::s4u::Mailbox* mailbox   = simgrid::s4u::Mailbox::by_name(mailbox_name);
 
   while (true) { // Master forcefully kills the workers by the end of the simulation
-    double* msg         = mailbox->get<double>();
+    auto msg            = mailbox->get_unique<double>();
     double compute_cost = *msg;
-    delete msg;
 
     // simgrid::s4u::this_actor::exec_init(compute_cost)->set_tracing_category(category)->wait();
     /* Long form:*/
index d8ce9e8..d58ed94 100644 (file)
@@ -33,13 +33,10 @@ static void receiver(const std::string& mailbox_name)
 
   XBT_INFO("Hello s4u, I'm ready to get any message you'd want on %s", mailbox->get_cname());
 
-  const auto* msg1 = mailbox->get<std::string>();
-  const auto* msg2 = mailbox->get<std::string>();
-  const auto* msg3 = mailbox->get<std::string>();
+  auto msg1 = mailbox->get_unique<std::string>();
+  auto msg2 = mailbox->get_unique<std::string>();
+  auto msg3 = mailbox->get_unique<std::string>();
   XBT_INFO("I received '%s', '%s' and '%s'", msg1->c_str(), msg2->c_str(), msg3->c_str());
-  delete msg1;
-  delete msg2;
-  delete msg3;
   XBT_INFO("I'm done. See you.");
 }
 
index 2f0f8ca..fa06d8e 100644 (file)
@@ -116,12 +116,11 @@ bool Peer::getPeersFromTracker()
   }
 
   try {
-    auto* answer = mailbox_->get<TrackerAnswer>(GET_PEERS_TIMEOUT);
+    auto answer = mailbox_->get_unique<TrackerAnswer>(GET_PEERS_TIMEOUT);
     // Add the peers the tracker gave us to our peer list.
     for (auto const& peer_id : answer->getPeers())
       if (id != peer_id)
         connected_peers.emplace(peer_id, Connection(peer_id));
-    delete answer;
   } catch (const simgrid::TimeoutException&) {
     XBT_DEBUG("Timeout expired when requesting peers to tracker");
     return false;
index 44f90eb..3d8e00c 100644 (file)
@@ -47,13 +47,12 @@ public:
 
   void joinChain()
   {
-    const auto* msg   = me->get<ChainMessage>();
-    prev              = msg->prev_;
-    next              = msg->next_;
-    total_pieces      = msg->num_pieces;
+    auto msg     = me->get_unique<ChainMessage>();
+    prev         = msg->prev_;
+    next         = msg->next_;
+    total_pieces = msg->num_pieces;
     XBT_DEBUG("Peer %s got a 'BUILD_CHAIN' message (prev: %s / next: %s)", me->get_cname(),
               prev ? prev->get_cname() : nullptr, next ? next->get_cname() : nullptr);
-    delete msg;
   }
 
   void forwardFile()
index e65a85c..f0e629a 100644 (file)
@@ -67,9 +67,8 @@ public:
   {
     double compute_cost;
     do {
-      const auto* msg = mailbox->get<double>();
+      auto msg     = mailbox->get_unique<double>();
       compute_cost = *msg;
-      delete msg;
 
       if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
         simgrid::s4u::this_actor::execute(compute_cost);
index f255aac..ddcba49 100644 (file)
@@ -54,9 +54,8 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    const auto* msg = mailbox->get<double>();
+    auto msg     = mailbox->get_unique<double>();
     compute_cost = *msg;
-    delete msg;
 
     if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
       simgrid::s4u::this_actor::execute(compute_cost);
index 0404107..8b4ed86 100644 (file)
@@ -16,12 +16,11 @@ static void pinger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai
 
   mailbox_out->put(payload, 1);
   /* - ... then wait for the (large) pong */
-  const auto* sender_time = mailbox_in->get<double>();
+  auto sender_time = mailbox_in->get_unique<double>();
 
   double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : large communication (bandwidth bound)");
   XBT_INFO("Pong time (bandwidth bound): %.3f", communication_time);
-  delete sender_time;
 }
 
 static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mailbox_out)
@@ -29,11 +28,10 @@ static void ponger(simgrid::s4u::Mailbox* mailbox_in, simgrid::s4u::Mailbox* mai
   XBT_INFO("Pong from mailbox %s to mailbox %s", mailbox_in->get_name().c_str(), mailbox_out->get_name().c_str());
 
   /* - Receive the (small) ping first ....*/
-  const auto* sender_time   = mailbox_in->get<double>();
+  auto sender_time          = mailbox_in->get_unique<double>();
   double communication_time = simgrid::s4u::Engine::get_clock() - *sender_time;
   XBT_INFO("Payload received : small communication (latency bound)");
   XBT_INFO("Ping time (latency bound) %f", communication_time);
-  delete sender_time;
 
   /*  - ... Then send a 1GB pong back (bandwidth bound) */
   auto* payload = new double(simgrid::s4u::Engine::get_clock());
index b65ea8e..7020c26 100644 (file)
@@ -47,13 +47,11 @@ static void communication_rx_fun(std::vector<std::string> args)
   const char* host_name         = simgrid::s4u::this_actor::get_host()->get_cname();
   simgrid::s4u::Mailbox* mbox   = simgrid::s4u::Mailbox::by_name(args.at(0));
 
-  const auto* payload       = mbox->get<struct s_payload>();
-  double clock_end          = simgrid::s4u::Engine::get_clock();
+  auto payload     = mbox->get_unique<struct s_payload>();
+  double clock_end = simgrid::s4u::Engine::get_clock();
 
   XBT_INFO("%s:%s to %s:%s => %g sec", payload->tx_host->get_cname(), payload->tx_actor_name, host_name, actor_name,
            clock_end - payload->clock_sta);
-
-  delete payload;
 }
 
 static void launch_communication_worker(s4u_Host* tx_host, s4u_Host* rx_host)
index d51ebbd..6aced3a 100644 (file)
@@ -74,9 +74,9 @@ static void peer(int argc, char** argv)
   long pending_finalize_messages = peers_count - 1;
   while (pending_finalize_messages > 0) {
     if (my_mbox->ready()) {
-      double start                = simgrid::s4u::Engine::get_clock();
-      const auto* received        = my_mbox->get<std::string>();
-      double waiting_time         = simgrid::s4u::Engine::get_clock() - start;
+      double start        = simgrid::s4u::Engine::get_clock();
+      auto received       = my_mbox->get_unique<std::string>();
+      double waiting_time = simgrid::s4u::Engine::get_clock() - start;
       xbt_assert(
           waiting_time == 0,
           "Expecting the waiting time to be 0 because the communication was supposedly ready, but got %f instead",
@@ -85,7 +85,6 @@ static void peer(int argc, char** argv)
       if (*received == "finalize") {
         pending_finalize_messages--;
       }
-      delete received;
     } else {
       XBT_INFO("Nothing ready to consume yet, I better sleep for a while");
       simgrid::s4u::this_actor::sleep_for(.01);
index 5377f38..0bc364f 100644 (file)
@@ -46,10 +46,9 @@ static void receiver(int, char**)
 {
   simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("receiver");
   XBT_INFO("Wait for the message.");
-  const auto* received = mbox->get<std::string>();
+  auto received = mbox->get_unique<std::string>();
 
   XBT_INFO("I got '%s'.", received->c_str());
-  delete received;
 }
 
 int main(int argc, char* argv[])
index c9f04be..aba2e8c 100644 (file)
@@ -89,11 +89,10 @@ public:
   {
     XBT_INFO("Wait for my first message");
     for (bool cont = true; cont;) {
-      const auto* received = mbox->get<std::string>();
+      auto received = mbox->get_unique<std::string>();
       XBT_INFO("I got a '%s'.", received->c_str());
       cont = (*received != "finalize"); // If it's a finalize message, we're done
       // Receiving the message was all we were supposed to do
-      delete received;
     }
   }
 };
index 5d7f920..cc92b27 100644 (file)
@@ -102,11 +102,10 @@ public:
   {
     XBT_INFO("Wait for my first message");
     for (bool cont = true; cont;) {
-      const auto* received = mbox->get<std::string>();
+      auto received = mbox->get_unique<std::string>();
       XBT_INFO("I got a '%s'.", received->c_str());
       cont = (*received != "finalize"); // If it's a finalize message, we're done
       // Receiving the message was all we were supposed to do
-      delete received;
     }
   }
 };
index 957dce2..30532c6 100644 (file)
@@ -71,11 +71,10 @@ static void receiver(int argc, char** argv)
 
   XBT_INFO("Wait for my first message");
   for (bool cont = true; cont;) {
-    const auto* received = mbox->get<std::string>();
+    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;
   }
 }
 
index af45373..51af163 100644 (file)
@@ -48,9 +48,8 @@ static void receiver()
 {
   ensure_other_tid();
 
-  const auto* payload = simgrid::s4u::Mailbox::by_name("some mailbox")->get<std::string>();
+  simgrid::s4u::Mailbox::by_name("some mailbox")->get_unique<std::string>();
   XBT_INFO("Task received");
-  delete payload;
 }
 
 static void maestro(void* /* data */)
index f9bf0a1..c69d369 100644 (file)
@@ -47,13 +47,12 @@ static void garbage_stack(void)
 static void coordinator()
 {
   int CS_used = 0;
-  const Message* m = nullptr;
   std::queue<simgrid::s4u::Mailbox*> requests;
 
   simgrid::s4u::Mailbox* mbox = simgrid::s4u::Mailbox::by_name("coordinator");
 
   while (true) {
-    m = mbox->get<Message>();
+    auto m = mbox->get_unique<Message>();
     if (m->kind == Message::Kind::REQUEST) {
       if (CS_used) {
         XBT_INFO("CS already used. Queue the request.");
@@ -81,7 +80,6 @@ static void coordinator()
         CS_used = 0;
       }
     }
-    delete m;
   }
 }
 
@@ -101,7 +99,7 @@ static void client(int id)
       XBT_INFO("Propositions changed : r=1, cs=0");
     }
 
-    const auto* grant = my_mailbox->get<Message>();
+    auto grant = my_mailbox->get_unique<Message>();
 
     if ((id == 1) && (grant->kind == Message::Kind::GRANT)) {
       cs = 1;
@@ -109,8 +107,6 @@ static void client(int id)
       XBT_INFO("Propositions changed : r=0, cs=1");
     }
 
-    delete grant;
-
     XBT_INFO("%d got the answer. Sleep a bit and release it", id);
 
     simgrid::s4u::this_actor::sleep_for(1);
index d192c08..e3c3902 100644 (file)
@@ -17,14 +17,11 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(example, "this example");
 
 static void server()
 {
-  int* received = nullptr;
+  std::unique_ptr<int> received;
   int count     = 0;
   while (count < N) {
-    if (received) {
-      delete received;
-      received = nullptr;
-    }
-    received = simgrid::s4u::Mailbox::by_name("mymailbox")->get<int>();
+    received.reset();
+    received = simgrid::s4u::Mailbox::by_name("mymailbox")->get_unique<int>();
     count++;
   }
   int value_got = *received;
index aaeb29b..4ae9710 100644 (file)
@@ -18,9 +18,8 @@ static int server(int worker_amount)
   int value_got             = -1;
   simgrid::s4u::Mailbox* mb = simgrid::s4u::Mailbox::by_name("server");
   for (int count = 0; count < worker_amount; count++) {
-    const auto* msg = mb->get<int>();
+    auto msg  = mb->get_unique<int>();
     value_got = *msg;
-    delete msg;
   }
   /*
    * We assert here that the last message we got (which overwrite any previously received message) is the one from the
index fca75f9..f4e6bba 100644 (file)
@@ -72,7 +72,7 @@ static void worker(int argc, char* argv[])
 
   XBT_DEBUG("Worker started");
 
-  const auto* payload = mbox->get<double>();
+  auto payload = mbox->get_unique<double>();
 
   count_finished--;
   if (count_finished == 0) {
@@ -83,7 +83,6 @@ static void worker(int argc, char* argv[])
 
   XBT_INFO("FLOW[%d] : Receive %.0f bytes from %s to %s", id, *payload, masternames[id], workernames[id]);
   XBT_DEBUG("FLOW[%d] : transferred in  %f seconds", id, elapsed_time);
-  delete payload;
 
   XBT_DEBUG("Finished");
 }
index 1927cdb..a04723a 100644 (file)
@@ -76,10 +76,9 @@ static void worker(std::vector<std::string> args)
   while (true) {
     try {
       XBT_INFO("Waiting a message on %s", mailbox->get_cname());
-      const auto* payload = mailbox->get<double>();
+      auto payload = mailbox->get_unique<double>();
       xbt_assert(payload != nullptr, "mailbox->get() failed");
       double comp_size = *payload;
-      delete payload;
       if (comp_size < 0) { /* - Exit when -1.0 is received */
         XBT_INFO("I'm done. See you!");
         break;
index ec4781c..7c8f001 100644 (file)
@@ -71,7 +71,7 @@ public:
 
     ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), simgrid::s4u::this_actor::get_cname(),
               from->get_cname());
-    delete from->get<std::string>();
+    from->get_unique<std::string>();
     log_action(action, simgrid::s4u::Engine::get_clock() - clock);
   }
 };
index dd8176b..5db0bc5 100644 (file)
@@ -39,9 +39,8 @@ static void worker()
 {
   auto mbox = simgrid::s4u::Mailbox::by_name("master_mailbox");
   while (true) {
-    const auto* task = mbox->get<Task>();
+    auto task = mbox->get_unique<Task>();
     if (task->name == "finalize") {
-      delete task;
       break;
     }
     // creating task and setting its category
@@ -49,7 +48,6 @@ static void worker()
         ->set_name(task->name)
         ->set_tracing_category(task->category)
         ->wait();
-    delete task;
   }
 }
 
index 509cb58..d55098d 100644 (file)
@@ -59,9 +59,8 @@ static void worker(std::vector<std::string> args)
   TRACE_host_variable_set(my_hostname, "task_computation", 0);
 
   while (true) {
-    const auto* task = mailbox->get<Task>();
+    auto task = mailbox->get_unique<Task>();
     if (task->name == "finalize") {
-      delete task;
       break;
     }
     // adding the task's cost to the variable "task_computation"
@@ -70,7 +69,6 @@ static void worker(std::vector<std::string> args)
         ->set_name(task->name)
         ->set_tracing_category(task->category)
         ->wait();
-    delete task;
   }
 
   XBT_DEBUG("Exiting now.");
index 5c12042..ae85a9a 100644 (file)
@@ -51,9 +51,8 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    const auto* msg   = mailbox->get<double>();
-    compute_cost      = *msg;
-    delete msg;
+    auto msg     = mailbox->get_unique<double>();
+    compute_cost = *msg;
 
     if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
       simgrid::s4u::this_actor::execute(compute_cost);
index 65bc4e5..29ebecf 100644 (file)
@@ -30,12 +30,10 @@ void MigrationRx::operator()()
       std::string("__mig_stage3:") + vm_->get_cname() + "(" + src_pm_->get_cname() + "-" + dst_pm_->get_cname() + ")";
 
   while (not received_finalize) {
-    const std::string* payload = mbox->get<std::string>();
+    auto payload = mbox->get_unique<std::string>();
 
     if (finalize_task_name == *payload)
       received_finalize = true;
-
-    delete payload;
   }
 
   // Here Stage 1, 2  and 3 have been performed.
@@ -353,7 +351,7 @@ void sg_vm_migrate(simgrid::s4u::VirtualMachine* vm, simgrid::s4u::Host* dst_pm)
   XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed");
   simgrid::s4u::Mailbox* mbox_ctl = simgrid::s4u::Mailbox::by_name(
       std::string("__mbox_mig_ctl:") + vm->get_cname() + "(" + src_pm->get_cname() + "-" + dst_pm->get_cname() + ")");
-  delete mbox_ctl->get<std::string>();
+  mbox_ctl->get_unique<std::string>();
   tx->join();
   rx->join();
 
index 56c0603..162dab9 100644 (file)
@@ -29,15 +29,13 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example")
 static int receiver(const char* box_name)
 {
   auto mb = simgrid::s4u::Mailbox::by_name(box_name);
-  const int* payload;
+  std::unique_ptr<int> payload;
 
-  payload = mb->get<int>();
+  payload = mb->get_unique<int>();
   MC_assert(*payload == 1);
-  delete payload;
 
-  payload = mb->get<int>();
+  payload = mb->get_unique<int>();
   MC_assert(*payload == 2);
-  delete payload;
 
   return 0;
 }
index 011b7e8..609bdd1 100644 (file)
@@ -40,10 +40,9 @@ static void commTX()
 
 static void commRX()
 {
-  const std::string* payload = nullptr;
   XBT_INFO("  Start RX");
   try {
-    payload = simgrid::s4u::Mailbox::by_name("comm")->get<std::string>();
+    auto payload = simgrid::s4u::Mailbox::by_name("comm")->get_unique<std::string>();
     XBT_INFO("  Receive message: %s", payload->c_str());
   } catch (const simgrid::HostFailureException&) {
     XBT_INFO("  Receive message: HOST_FAILURE");
@@ -51,7 +50,6 @@ static void commRX()
     XBT_INFO("  Receive message: TRANSFER_FAILURE");
   }
 
-  delete payload;
   XBT_INFO("  RX Done");
 }
 
index bb98a89..bfd8843 100644 (file)
@@ -35,15 +35,14 @@ static void master()
 
 static void worker()
 {
-  const std::string* payload     = nullptr;
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("comm");
 
   XBT_INFO("Worker receiving");
   try {
-    payload = mailbox->get<std::string>();
+    auto payload = mailbox->get_unique<std::string>();
+    XBT_DEBUG("Received message: %s", payload->c_str());
   } catch (const simgrid::HostFailureException&) {
     XBT_DEBUG("The host has been turned off, this was expected");
-    delete payload;
     return;
   }
 
index 805f34a..dc0b2de 100644 (file)
@@ -10,25 +10,23 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u example")
 
 static void worker()
 {
-  const std::string* payload;
   simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("jupi");
 
   while (true) {
+    std::unique_ptr<std::string> payload;
     try {
-      payload = mailbox->get<std::string>();
+      payload = mailbox->get_unique<std::string>();
     } catch (const simgrid::HostFailureException&) {
       XBT_DEBUG("The host has been turned off, this was expected");
       return;
     }
 
     if (*payload == "finalize") {
-      delete payload;
       break;
     }
     simgrid::s4u::this_actor::execute(5E7);
 
     XBT_INFO("Task \"%s\" done", payload->c_str());
-    delete payload;
   }
   XBT_INFO("I'm done. See you!");
 }
index 04e7ac4..034d263 100644 (file)
@@ -24,11 +24,10 @@ static void server()
   XBT_INFO("Mailbox::listen_from() returns %ld (should return my pid, which is %ld)", mailbox->listen_from(),
            simgrid::s4u::this_actor::get_pid());
 
-  const std::string* res = mailbox->get<std::string>();
+  auto res = mailbox->get_unique<std::string>();
 
   xbt_assert(*res == "Some data", "Data received: %s", res->c_str());
   XBT_INFO("Data successfully received from regular mailbox");
-  delete res;
   sendComm->wait();
 
   simgrid::s4u::Mailbox* mailbox2 = simgrid::s4u::Mailbox::by_name("mailbox2");
@@ -39,9 +38,8 @@ static void server()
   xbt_assert(mailbox2->listen()); // used to break.
   XBT_INFO("Task listen works on asynchronous mailboxes");
 
-  res = mailbox2->get<std::string>();
+  res = mailbox2->get_unique<std::string>();
   xbt_assert(*res == "More data");
-  delete res;
 
   XBT_INFO("Data successfully received from asynchronous mailbox");
 }
index c9aa53d..50ed51e 100644 (file)
@@ -33,10 +33,9 @@ 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* ptr = box->get<int>();
+    auto ptr = box->get_unique<int>();
     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);
 }
index c05e9cc..06522b0 100644 (file)
@@ -33,10 +33,9 @@ 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* ptr = box->get<int>();
+    auto ptr = box->get_unique<int>();
     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);
 }
index d676ff5..9352f45 100644 (file)
@@ -127,16 +127,14 @@ static void server()
 
   XBT_INFO("Server waiting for transfers ...");
   while (true) {
-    const std::string* msg = mailbox->get<std::string>();
+    auto msg = mailbox->get_unique<std::string>();
     if (*msg == "finalize") { // Shutdown ...
-      delete msg;
       break;
     } else { // Receive file to save
       size_t pos              = msg->find(' ');
       std::string dest        = msg->substr(0, pos);
       sg_size_t size_to_write = std::stoull(msg->substr(pos + 1));
       write_local_file(dest, size_to_write);
-      delete msg;
     }
   }