-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Segmentation fault when adding a short-lived node to an executor
Ref: ros2/rmw_fastrtps#777 Signed-off-by: Tomoya Fujita <[email protected]>
- Loading branch information
1 parent
cdb2440
commit b0b057f
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |