Skip to content

Commit

Permalink
fix: join execute thread on destruction
Browse files Browse the repository at this point in the history
  • Loading branch information
domire8 committed Oct 9, 2024
1 parent c749a2a commit 16a18ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class Component : public rclcpp::Node, public ComponentInterface {
explicit Component(const rclcpp::NodeOptions& node_options, const std::string& fallback_name = "Component");

/**
* @brief Virtual default destructor.
* @brief Destructor that joins the thread if necessary.
*/
virtual ~Component() = default;
virtual ~Component();

protected:
/**
Expand Down
6 changes: 6 additions & 0 deletions source/modulo_components/src/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Component::Component(const NodeOptions& node_options, const std::string& fallbac
this->add_predicate("in_error_state", false);
}

Component::~Component() {
if (this->execute_thread_.joinable()) {
this->execute_thread_.join();
}
}

void Component::step() {
try {
this->evaluate_periodic_callbacks();
Expand Down

0 comments on commit 16a18ea

Please sign in to comment.