Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines for 2022.
[simgrid.git] / teshsuite / s4u / wait-any-for / wait-any-for.cpp
index a206d6a..5190d4a 100644 (file)
@@ -1,3 +1,8 @@
+/* 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. */
+
 #include <cstdlib>
 #include <iostream>
 #include <string>
@@ -16,21 +21,21 @@ static void worker()
   auto put1 = mbox->put_async(&input1, 1000 * 1000 * 500);
   auto put2 = mbox->put_async(&input2, 1000 * 1000 * 1000);
 
-  int * out1;
-  auto get1 = mbox->get_async((void**)&out1);
+  int* out1;
+  auto get1 = mbox->get_async<int>(&out1);
 
-  int * out2;
-  auto get2 = mbox->get_async((void**)&out2);
+  int* out2;
+  auto get2 = mbox->get_async<int>(&out2);
 
   XBT_INFO("All comms have started");
   std::vector<simgrid::s4u::CommPtr> comms = {put1, put2, get1, get2};
 
-  while (!comms.empty()) {
-    int index = simgrid::s4u::Comm::wait_any_for(&comms, 0.5);
+  while (not comms.empty()) {
+    ssize_t index = simgrid::s4u::Comm::wait_any_for(comms, 0.5);
     if (index < 0)
       XBT_INFO("wait_any_for: Timeout reached");
     else {
-      XBT_INFO("wait_any_for: A comm finished (index=%d, #comms=%zu)", index, comms.size());
+      XBT_INFO("wait_any_for: A comm finished (index=%zd, #comms=%zu)", index, comms.size());
       comms.erase(comms.begin() + index);
     }
   }
@@ -44,7 +49,7 @@ int main(int argc, char* argv[])
 {
   simgrid::s4u::Engine e(&argc, argv);
   e.load_platform(argv[1]);
-  simgrid::s4u::Actor::create("worker", simgrid::s4u::Host::by_name("Tremblay"), worker);
+  simgrid::s4u::Actor::create("worker", e.host_by_name("Tremblay"), worker);
   e.run();
   return 0;
 }