Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix tesh with new dependencies on Mutex
[simgrid.git] / teshsuite / s4u / ns3-simultaneous-send-rcv / ns3-simultaneous-send-rcv.cpp
index fac6475..47f7b0e 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-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. */
@@ -16,11 +16,9 @@ const int nb_message_to_send = 5;
 const double sleep_time      = 5;
 const int nb_sender          = 100;
 
-int nb_messages_sent = 0;
-
-simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
-
 static void test_send(){
+  simgrid::s4u::Mailbox* box  = simgrid::s4u::Mailbox::by_name("test");
+  static int nb_messages_sent = 0;
   for (int nb_message = 0; nb_message < nb_message_to_send; nb_message++) {
     nb_messages_sent++;
     XBT_VERB("start sending test #%i", nb_messages_sent);
@@ -31,12 +29,12 @@ static void test_send(){
 }
 
 static void test_receive(){
+  simgrid::s4u::Mailbox* box = simgrid::s4u::Mailbox::by_name("test");
   for (int nb_message = 0; nb_message < nb_message_to_send * nb_sender; nb_message++) {
     XBT_VERB("waiting for messages");
-    int* ptr = (int*)(box->get());
+    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);
 }
@@ -45,7 +43,7 @@ static void test_receive(){
 int main(int argc, char *argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
+
   e.load_platform(argv[1]);
 
   auto hosts = e.get_all_hosts();