Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
save some hidden calls to Engine::get_instance
[simgrid.git] / teshsuite / s4u / actor-suspend / actor-suspend.cpp
index 14bf657..657b2fc 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2020-2021. 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. */
@@ -6,10 +6,10 @@
 // This is the MWE of https://framagit.org/simgrid/simgrid/-/issues/50
 // The problem was occurring when suspending an actor that will be executed later in the same scheduling round
 
+#include <cstdio>
+#include <cstdlib>
 #include <iostream>
 #include <simgrid/s4u.hpp>
-#include <stdio.h>
-#include <stdlib.h>
 #include <vector>
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(mwe, "Minimum Working Example");
@@ -22,7 +22,7 @@ public:
   {
     XBT_INFO("Starting.");
     auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
-    int data     = *(int*)mailbox->get();
+    int data     = *mailbox->get<int>();
     XBT_INFO("Got %d at the end", data);
   }
 };
@@ -41,7 +41,7 @@ public:
 
     XBT_INFO("Sending a message to the receiver...");
     auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
-    int data     = 42;
+    static int data = 42;
     mailbox->put(&data, 4);
 
     XBT_INFO("Done!");
@@ -50,15 +50,15 @@ public:
 
 int main(int argc, char** argv)
 {
-  const simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv);
+  simgrid::s4u::Engine engine(&argc, argv);
 
-  engine->load_platform(argv[1]);
-  simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Tremblay");
+  engine.load_platform(argv[1]);
+  simgrid::s4u::Host* host = engine.host_by_name("Tremblay");
 
   simgrid::s4u::Actor::create("Suspender", host, Suspender());
   receiver = simgrid::s4u::Actor::create("Receiver", host, Receiver());
 
-  engine->run();
+  engine.run();
 
   return 0;
 }