Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More information on actor death in monkey's test case
[simgrid.git] / teshsuite / s4u / ns3-from-src-to-itself / ns3-from-src-to-itself.cpp
index dbe6027952639cdade8526f7b05a393e26d65bc8..49e4c3963f2e3985eeae8681579fd1598ec925ad 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2019-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2019-2022. 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. */
@@ -13,32 +13,28 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u tests");
 
 const int payload            = 1000;
 const int nb_message_to_send = 5;
-// const double sleep_time      = 5;
 const int nb_sender = 2;
 
-int nb_messages_sent = 0;
-
-simgrid::s4u::Mailbox* box;
-
 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);
     box->put(new int(nb_messages_sent), payload);
     XBT_VERB("done sending test #%i", nb_messages_sent);
-    //    simgrid::s4u::this_actor::sleep_until(sleep_time * (nb_message + 1));
   }
 }
 
 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);
 }
@@ -49,12 +45,10 @@ int main(int argc, char* argv[])
 
   e.load_platform(argv[1]);
 
-  auto host       = e.get_all_hosts()[0];
-  auto receiver   = simgrid::s4u::Actor::create("receiver", host, test_receive);
-  auto send_same  = simgrid::s4u::Actor::create("send_same", host, test_send);
-  auto send_other = simgrid::s4u::Actor::create("send_other", e.get_all_hosts()[1], test_send);
-
-  box = simgrid::s4u::Mailbox::by_name("test");
+  auto hosts = e.get_all_hosts();
+  simgrid::s4u::Actor::create("receiver", hosts[0], test_receive);
+  simgrid::s4u::Actor::create("send_same", hosts[0], test_send);
+  simgrid::s4u::Actor::create("send_other", hosts[1], test_send);
 
   e.run();