From b0b057fc253f38def602701122828ad9cbf0df1d Mon Sep 17 00:00:00 2001 From: Tomoya Fujita Date: Mon, 9 Sep 2024 13:57:58 -0700 Subject: [PATCH] Segmentation fault when adding a short-lived node to an executor Ref: https://github.com/ros2/rmw_fastrtps/issues/777 Signed-off-by: Tomoya Fujita --- prover_rclcpp/CMakeLists.txt | 1 + prover_rclcpp/src/rmw_fastrtps_777.cpp | 39 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 prover_rclcpp/src/rmw_fastrtps_777.cpp diff --git a/prover_rclcpp/CMakeLists.txt b/prover_rclcpp/CMakeLists.txt index 3df083a..28b3e70 100644 --- a/prover_rclcpp/CMakeLists.txt +++ b/prover_rclcpp/CMakeLists.txt @@ -167,6 +167,7 @@ custom_executable(rmw_fastrtps_554) custom_executable(rmw_fastrtps_555) custom_executable(rmw_fastrtps_646) custom_executable(rmw_fastrtps_728) +custom_executable(rmw_fastrtps_777) #custom_executable(ros2_644) #custom_executable(ros2_946_pub) diff --git a/prover_rclcpp/src/rmw_fastrtps_777.cpp b/prover_rclcpp/src/rmw_fastrtps_777.cpp new file mode 100644 index 0000000..56c6ac3 --- /dev/null +++ b/prover_rclcpp/src/rmw_fastrtps_777.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +#include +#include + +auto function() -> void +{ + rclcpp::init(0, nullptr); + + rclcpp::executors::MultiThreadedExecutor executor; + + std::atomic_bool stop_spinning{false}; + auto spinner_thread{std::thread([&] { + while (rclcpp::ok() && !stop_spinning.load()) { + executor.spin_some(); + } + })}; + + { + auto node{std::make_shared("node")}; + executor.add_node(node); + } + + stop_spinning.store(true); + spinner_thread.join(); + + rclcpp::shutdown(); +} + +auto main() -> int +{ + while (true) { + function(); + } + + return 0; +}