From ff3f57e561b45fec191d2f19d8904bde87a37855 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 27 Apr 2021 14:44:10 +0200 Subject: [PATCH] Fix ActivityImpl::wait_for to not cancel the activity on timeout. This should improve issue simgrid/simgrid#47. Some tests are broken by this commit, and should be fixed soon. --- ChangeLog | 4 ++++ src/kernel/activity/ActivityImpl.cpp | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 002aa947a4..9ea5af1a56 100644 --- 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. diff --git a/src/kernel/activity/ActivityImpl.cpp b/src/kernel/activity/ActivityImpl.cpp index 16e3bce599..70e80323d3 100644 --- a/src/kernel/activity/ActivityImpl.cpp +++ b/src/kernel/activity/ActivityImpl.cpp @@ -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 @@ -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(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_); } } -- 2.20.1