]> AND Public Git Repository - simgrid.git/blobdiff - teshsuite/s4u/actor-suspend/actor-suspend.cpp
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'pikachuyann/simgrid-stoprofiles'
[simgrid.git] / teshsuite / s4u / actor-suspend / actor-suspend.cpp
index 60c7e51c13000be69ac256256e7bc80b1f78990d..e157191735b7671dd1ae0e19bad7358315fa2177 100644 (file)
@@ -4,12 +4,12 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 // This is the MWE of https://framagit.org/simgrid/simgrid/-/issues/50
-// The problem was occuring when suspending an actor that will be executed later in the same scheduling round
+// 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");
@@ -17,28 +17,20 @@ XBT_LOG_NEW_DEFAULT_CATEGORY(mwe, "Minimum Working Example");
 simgrid::s4u::ActorPtr receiver;
 
 class Receiver {
-
 public:
-  void operator()()
+  void operator()() const
   {
     XBT_INFO("Starting.");
-    simgrid::s4u::Mailbox* mailbox = simgrid::s4u::Mailbox::by_name("receiver");
-    void* data                     = (void*)2;
-    data                           = mailbox->get();
-    xbt_die("get() has returned (even though it shouldn't!) with a %s message",
-            (data == nullptr ? "null" : "non-null"));
+    auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
+    int data     = *(int*)mailbox->get();
+    XBT_INFO("Got %d at the end", data);
   }
 };
 
 class Suspender {
-
 public:
-  void operator()()
+  void operator()() const
   {
-
-    // If we sleep a bit here, this MWE works because the suspender is not trying to suspend someone executed later in
-    // the same scheduling round simgrid::s4u::this_actor::sleep_for(0.01);
-
     XBT_INFO("Suspend the receiver...");
     receiver->suspend();
     XBT_INFO("Resume the receiver...");
@@ -46,14 +38,19 @@ public:
 
     XBT_INFO("Sleeping 10 sec...");
     simgrid::s4u::this_actor::sleep_for(10);
+
+    XBT_INFO("Sending a message to the receiver...");
+    auto mailbox = simgrid::s4u::Mailbox::by_name("receiver");
+    int data     = 42;
+    mailbox->put(&data, 4);
+
     XBT_INFO("Done!");
   }
 };
 
 int main(int argc, char** argv)
 {
-
-  simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv);
+  const simgrid::s4u::Engine* engine = new simgrid::s4u::Engine(&argc, argv);
 
   engine->load_platform(argv[1]);
   simgrid::s4u::Host* host = simgrid::s4u::Host::by_name("Tremblay");