From 16a18ea0cb1dd5f0eebec4b125b9d79c913fe6ef Mon Sep 17 00:00:00 2001 From: Dominic Reber Date: Wed, 9 Oct 2024 13:30:27 +0200 Subject: [PATCH] fix: join execute thread on destruction --- .../include/modulo_components/Component.hpp | 4 ++-- source/modulo_components/src/Component.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/source/modulo_components/include/modulo_components/Component.hpp b/source/modulo_components/include/modulo_components/Component.hpp index 440b2341..429dbcb0 100644 --- a/source/modulo_components/include/modulo_components/Component.hpp +++ b/source/modulo_components/include/modulo_components/Component.hpp @@ -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: /** diff --git a/source/modulo_components/src/Component.cpp b/source/modulo_components/src/Component.cpp index cb0ab8af..59f300c0 100644 --- a/source/modulo_components/src/Component.cpp +++ b/source/modulo_components/src/Component.cpp @@ -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();