Skip to content

Commit

Permalink
Segmentation fault when adding a short-lived node to an executor
Browse files Browse the repository at this point in the history
  Ref: ros2/rmw_fastrtps#777

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Sep 9, 2024
1 parent cdb2440 commit b0b057f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions prover_rclcpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
39 changes: 39 additions & 0 deletions prover_rclcpp/src/rmw_fastrtps_777.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <atomic>
#include <memory>
#include <thread>

#include <rclcpp/executors/multi_threaded_executor.hpp>
#include <rclcpp/node.hpp>

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<rclcpp::Node>("node")};
executor.add_node(node);
}

stop_spinning.store(true);
spinner_thread.join();

rclcpp::shutdown();
}

auto main() -> int
{
while (true) {
function();
}

return 0;
}

0 comments on commit b0b057f

Please sign in to comment.