Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix ActivityImpl::wait_for to not cancel the activity on timeout.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Apr 2021 12:44:10 +0000 (14:44 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 3 May 2021 14:46:14 +0000 (16:46 +0200)
This should improve issue simgrid/simgrid#47.

Some tests are broken by this commit, and should be fixed soon.

ChangeLog
src/kernel/activity/ActivityImpl.cpp

index 002aa94..9ea5af1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,10 @@
 
 SimGrid (3.27.1) NOT RELEASED YET (v3.28 expected June 21. 2021, 03:32 UTC)
 
+S4U:
+ - Fixed a bug where Activity::wait_for() killed the activity on timeout.
+   Explicitly cancel the activity to get back to previous behavior.
+
 LUA:
  - Lua platform files are deprecated. Their support will be dropped after v3.31.
 
index 16e3bce..70e8032 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "src/kernel/activity/ActivityImpl.hpp"
 #include "simgrid/modelchecker.h"
+#include "src/kernel/activity/SynchroRaw.hpp"
+#include "src/kernel/actor/SimcallObserver.hpp"
 #include "src/mc/mc_replay.hpp"
 #include "src/simix/smx_private.hpp"
 #include <boost/range/algorithm.hpp>
@@ -74,15 +76,19 @@ void ActivityImpl::wait_for(actor::ActorImpl* issuer, double timeout)
   xbt_assert(not MC_is_active() && not MC_record_replay_is_active(), "MC is currently not supported here.");
 
   /* If the synchro is already finished then perform the error handling */
-  if (state_ != State::RUNNING)
-    finish();
-  else if (timeout == 0.) {
-    // still running and timeout == 0 ? We need to report a timeout
-    state_ = State::TIMEOUT;
+  if (state_ != State::RUNNING) {
     finish();
   } else {
     /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */
-    set_timeout(timeout);
+    RawImplPtr synchro(new RawImpl([this, issuer]() {
+      this->unregister_simcall(&issuer->simcall_);
+      issuer->waiting_synchro_ = nullptr;
+      auto* observer = dynamic_cast<kernel::actor::ActivityWaitSimcall*>(issuer->simcall_.observer_);
+      xbt_assert(observer != nullptr);
+      observer->set_result(true);
+    }));
+    synchro->set_host(issuer->get_host()).set_timeout(timeout).start();
+    synchro->register_simcall(&issuer->simcall_);
   }
 }