Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Try to make timeouted semaphores robust to actors death
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 25 Feb 2022 22:41:30 +0000 (23:41 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Fri, 25 Feb 2022 22:41:37 +0000 (23:41 +0100)
Unfortunately, I cannot test it right now (the test is not written,
plus asynchronous semaphores are not exported in s4u to ease the
writting of tests), but it's failing for a user that kills a lot of
actors at random instants.

src/kernel/activity/SemaphoreImpl.cpp
src/kernel/activity/SemaphoreImpl.hpp

index 9e340d7..03998f2 100644 (file)
@@ -54,16 +54,10 @@ void SemAcquisitionImpl::finish()
         set_state(State::DONE);
 
       } else { // we have to report that timeout
-        /* Remove myself from the list of interested parties */
-        auto issuer = get_issuer();
-        auto it     = std::find_if(semaphore_->ongoing_acquisitions_.begin(), semaphore_->ongoing_acquisitions_.end(),
-                                   [issuer](SemAcquisitionImplPtr acqui) { return acqui->get_issuer() == issuer; });
-        xbt_assert(it != semaphore_->ongoing_acquisitions_.end(),
-                   "Cannot find myself in the waiting queue that I have to leave");
-        semaphore_->ongoing_acquisitions_.erase(it);
+        cancel(); // Unregister the acquisition from the semaphore
 
         /* Return to the englobing simcall that the wait_for timeouted */
-        auto* observer = dynamic_cast<kernel::actor::SemAcquireSimcall*>(issuer->simcall_.observer_);
+        auto* observer = dynamic_cast<kernel::actor::SemAcquireSimcall*>(get_issuer()->simcall_.observer_);
         xbt_assert(observer != nullptr);
         observer->set_result(true);
       }
@@ -75,7 +69,16 @@ void SemAcquisitionImpl::finish()
   simcall->issuer_->waiting_synchro_ = nullptr;
   simcall->issuer_->simcall_answer();
 }
-
+void SemAcquisitionImpl::cancel()
+{
+  /* Remove myself from the list of interested parties */
+  auto issuer = get_issuer();
+  auto it     = std::find_if(semaphore_->ongoing_acquisitions_.begin(), semaphore_->ongoing_acquisitions_.end(),
+                             [issuer](SemAcquisitionImplPtr acqui) { return acqui->get_issuer() == issuer; });
+  xbt_assert(it != semaphore_->ongoing_acquisitions_.end(),
+             "Cannot find myself in the waiting queue that I have to leave");
+  semaphore_->ongoing_acquisitions_.erase(it);
+}
 SemAcquisitionImplPtr SemaphoreImpl::acquire_async(actor::ActorImpl* issuer)
 {
   auto res = SemAcquisitionImplPtr(new kernel::activity::SemAcquisitionImpl(issuer, this), true);
index 8d25263..460fc51 100644 (file)
@@ -37,6 +37,7 @@ public:
   void wait_for(actor::ActorImpl* issuer, double timeout) override;
   void post() override;
   void finish() override;
+  void cancel() override;
   void set_exception(actor::ActorImpl* issuer) override
   { /* nothing to do */
   }