From 3c038eac822ac8fbc74a278571574a13de0bd17f Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 6 Jun 2017 03:46:51 +0200 Subject: [PATCH] fix S4U chord example \o/ --- examples/s4u/dht-chord/node.cpp | 26 +++++++++++++----------- examples/s4u/dht-chord/s4u_dht-chord.hpp | 10 ++++----- src/simix/ActorImpl.cpp | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/s4u/dht-chord/node.cpp b/examples/s4u/dht-chord/node.cpp index d0ee0e92a2..98058a2b0a 100644 --- a/examples/s4u/dht-chord/node.cpp +++ b/examples/s4u/dht-chord/node.cpp @@ -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; + } } } } diff --git a/examples/s4u/dht-chord/s4u_dht-chord.hpp b/examples/s4u/dht-chord/s4u_dht-chord.hpp index 60f3d6b964..a415bf9bd3 100644 --- a/examples/s4u/dht-chord/s4u_dht-chord.hpp +++ b/examples/s4u/dht-chord/s4u_dht-chord.hpp @@ -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(data); handleMessage(message); - } else { - comm_receive->cancel(); + comm_receive = nullptr; + data = nullptr; } now = simgrid::s4u::Engine::getClock(); } diff --git a/src/simix/ActorImpl.cpp b/src/simix/ActorImpl.cpp index f725f86c22..2c59aab6d3 100644 --- a/src/simix/ActorImpl.cpp +++ b/src/simix/ActorImpl.cpp @@ -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(process->comms.front()); + comm->cancel(); } XBT_DEBUG("%p should not be run anymore",process); -- 2.20.1