Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix S4U chord example \o/
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 6 Jun 2017 01:46:51 +0000 (03:46 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Tue, 6 Jun 2017 01:46:51 +0000 (03:46 +0200)
examples/s4u/dht-chord/node.cpp
examples/s4u/dht-chord/s4u_dht-chord.hpp
src/simix/ActorImpl.cpp

index d0ee0e9..98058a2 100644 (file)
@@ -120,18 +120,20 @@ void Node::notifyAndQuit()
     }
   }
 
-  // send the SUCCESSOR_LEAVING to our predecessor
-  ChordMessage* succ_msg = new ChordMessage(SUCCESSOR_LEAVING);
-  succ_msg->request_id   = fingers_[0];
-  succ_msg->answer_to    = mailbox_;
-  XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
-
-  try {
-    simgrid::s4u::this_actor::send(simgrid::s4u::Mailbox::byName(std::to_string(pred_id_)), succ_msg, 10, timeout);
-  } catch (xbt_ex& e) {
-    if (e.category == timeout_error) {
-      XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
-      delete succ_msg;
+  if (pred_id_ != -1) {
+    // send the SUCCESSOR_LEAVING to our predecessor (only if I have one)
+    ChordMessage* succ_msg = new ChordMessage(SUCCESSOR_LEAVING);
+    succ_msg->request_id   = fingers_[0];
+    succ_msg->answer_to    = mailbox_;
+    XBT_DEBUG("Sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
+
+    try {
+      simgrid::s4u::this_actor::send(simgrid::s4u::Mailbox::byName(std::to_string(pred_id_)), succ_msg, 10, timeout);
+    } catch (xbt_ex& e) {
+      if (e.category == timeout_error) {
+        XBT_DEBUG("Timeout expired when sending a 'SUCCESSOR_LEAVING' to my predecessor %d", pred_id_);
+        delete succ_msg;
+      }
     }
   }
 }
index 60f3d6b..a415bf9 100644 (file)
@@ -126,10 +126,10 @@ public:
     double next_fix_fingers_date       = start_time_ + PERIODIC_FIX_FINGERS_DELAY;
     double next_check_predecessor_date = start_time_ + PERIODIC_CHECK_PREDECESSOR_DELAY;
     double next_lookup_date            = start_time_ + PERIODIC_LOOKUP_DELAY;
-
+    simgrid::s4u::CommPtr comm_receive = nullptr;
     while ((now < (start_time_ + deadline_)) && now < MAX_SIMULATION_TIME) {
-      data                               = nullptr;
-      simgrid::s4u::CommPtr comm_receive = simgrid::s4u::this_actor::irecv(mailbox_, &data);
+      if (comm_receive == nullptr)
+        comm_receive = simgrid::s4u::this_actor::irecv(mailbox_, &data);
       while ((now < (start_time_ + deadline_)) && now < MAX_SIMULATION_TIME && not comm_receive->test()) {
         // no task was received: make some periodic calls
         if (now >= next_stabilize_date) {
@@ -154,8 +154,8 @@ public:
       if (data != nullptr) {
         ChordMessage* message = static_cast<ChordMessage*>(data);
         handleMessage(message);
-      } else {
-        comm_receive->cancel();
+        comm_receive = nullptr;
+        data         = nullptr;
       }
       now = simgrid::s4u::Engine::getClock();
     }
index f725f86..2c59aab 100644 (file)
@@ -99,7 +99,6 @@ void SIMIX_process_cleanup(smx_actor_t process)
 
     /* make sure no one will finish the comm after this process is destroyed,
      * because src_proc or dst_proc would be an invalid pointer */
-    comm->cancel();
 
     if (comm->src_proc == process) {
       XBT_DEBUG("Found an unfinished send comm %p (detached = %d), state %d, src = %p, dst = %p",
@@ -125,6 +124,7 @@ void SIMIX_process_cleanup(smx_actor_t process)
     }
     process->comms.pop_front();
     synchro = static_cast<smx_activity_t>(process->comms.front());
+    comm->cancel();
   }
 
   XBT_DEBUG("%p should not be run anymore",process);