From 3f2a87241d587053e5dcce5c489c60c500a26843 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Wed, 2 Feb 2022 11:03:13 +0100 Subject: [PATCH] better handling of ActivityImpl::wait_for with dying actors --- examples/c/actor-exiting/actor-exiting.tesh | 2 +- .../cpp/actor-exiting/s4u-actor-exiting.tesh | 2 +- src/kernel/activity/ActivityImpl.cpp | 24 ++++++++++--------- src/kernel/activity/CommImpl.cpp | 7 ++++-- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/examples/c/actor-exiting/actor-exiting.tesh b/examples/c/actor-exiting/actor-exiting.tesh index 9ca76856b1..0c05238b0a 100644 --- a/examples/c/actor-exiting/actor-exiting.tesh +++ b/examples/c/actor-exiting/actor-exiting.tesh @@ -8,6 +8,6 @@ $ ${bindir:=.}/c-actor-exiting ${platfdir}/small_platform.xml "--log=root.fmt:[% > [ 3.000000] (maestro@) Oops! Deadlock or code not perfectly clean. > [ 3.000000] (maestro@) 1 actors are still running, waiting for something. > [ 3.000000] (maestro@) Legend of the following listing: "Actor (@): " -> [ 3.000000] (maestro@) Actor 3 (C@Ginette): waiting for synchronization activity 0xdeadbeef () in state WAITING to finish +> [ 3.000000] (maestro@) Actor 3 (C@Ginette): waiting for communication activity 0xdeadbeef () in state WAITING to finish > [ 3.000000] (C@Ginette) I was killed! > [ 3.000000] (C@Ginette) The backtrace would be displayed here if --log=no_loc would not have been passed diff --git a/examples/cpp/actor-exiting/s4u-actor-exiting.tesh b/examples/cpp/actor-exiting/s4u-actor-exiting.tesh index c5a67422ca..c46a1188c1 100644 --- a/examples/cpp/actor-exiting/s4u-actor-exiting.tesh +++ b/examples/cpp/actor-exiting/s4u-actor-exiting.tesh @@ -12,7 +12,7 @@ $ ${bindir:=.}/s4u-actor-exiting ${platfdir}/small_platform.xml "--log=root.fmt: > [ 3.000000] (maestro@) Oops! Deadlock or code not perfectly clean. > [ 3.000000] (maestro@) 1 actors are still running, waiting for something. > [ 3.000000] (maestro@) Legend of the following listing: "Actor (@): " -> [ 3.000000] (maestro@) Actor 3 (C@Ginette): waiting for synchronization activity 0xdeadbeef () in state WAITING to finish +> [ 3.000000] (maestro@) Actor 3 (C@Ginette): waiting for communication activity 0xdeadbeef () in state WAITING to finish > [ 3.000000] (C@Ginette) I was killed! > [ 3.000000] (C@Ginette) The backtrace would be displayed here if --log=no_loc would not have been passed > [ 3.000000] (maestro@) Actor C terminates now diff --git a/src/kernel/activity/ActivityImpl.cpp b/src/kernel/activity/ActivityImpl.cpp index 3840cc8515..c95beb4b4b 100644 --- a/src/kernel/activity/ActivityImpl.cpp +++ b/src/kernel/activity/ActivityImpl.cpp @@ -118,6 +118,8 @@ void ActivityImpl::wait_for(actor::ActorImpl* issuer, double timeout) if (state_ != State::WAITING && state_ != State::RUNNING) { finish(); } else { + /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */ + /* Comms handle that a bit differently of the other activities */ auto* comm = dynamic_cast(this); if (comm != nullptr) { resource::Action* sleep = issuer->get_host()->get_cpu()->sleep(timeout); @@ -127,18 +129,18 @@ void ActivityImpl::wait_for(actor::ActorImpl* issuer, double timeout) comm->src_timeout_ = sleep; else comm->dst_timeout_ = sleep; + } else { + RawImplPtr synchro(new RawImpl([this, issuer]() { + this->unregister_simcall(&issuer->simcall_); + issuer->waiting_synchro_ = nullptr; + issuer->exception_ = 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_); } - /* we need a sleep action (even when the timeout is infinite) to be notified of host failures */ - RawImplPtr synchro(new RawImpl([this, issuer]() { - this->unregister_simcall(&issuer->simcall_); - issuer->waiting_synchro_ = nullptr; - issuer->exception_ = 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_); } } diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index 44a6e8083f..53537a531d 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -599,8 +599,11 @@ void CommImpl::finish() if (not simcall->issuer_->get_host()->is_on()) { simcall->issuer_->context_->set_wannadie(); } else { - set_exception(simcall->issuer_); - simcall->issuer_->simcall_answer(); + // Do not answer to dying actors + if (not simcall->issuer_->context_->wannadie()) { + set_exception(simcall->issuer_); + simcall->issuer_->simcall_answer(); + } } simcall->issuer_->waiting_synchro_ = nullptr; -- 2.20.1