Skip to content

Commit 8cd4d47

Browse files
authored
Avoid unecessary creation of MultiThreadedExecutor (#3090)
Signed-off-by: solonovamax <solonovamax@12oclockpoint.com>
1 parent f145c9e commit 8cd4d47

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

rclcpp_components/src/component_container_mt.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@ int main(int argc, char * argv[])
2424
/// Component container with a multi-threaded executor.
2525
rclcpp::init(argc, argv);
2626

27-
auto exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
28-
auto node = std::make_shared<rclcpp_components::ComponentManager>();
27+
rclcpp::executors::MultiThreadedExecutor::SharedPtr exec = nullptr;
28+
const auto node = std::make_shared<rclcpp_components::ComponentManager>();
2929
if (node->has_parameter("thread_num")) {
3030
const auto thread_num = node->get_parameter("thread_num").as_int();
3131
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>(
3232
rclcpp::ExecutorOptions{}, thread_num);
33-
node->set_executor(exec);
3433
} else {
35-
node->set_executor(exec);
34+
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
3635
}
36+
node->set_executor(exec);
3737
exec->add_node(node);
3838
exec->spin();
3939

0 commit comments

Comments
 (0)