Skip to content

Commit 3a053fb

Browse files
Avoid unecessary creation of MultiThreadedExecutor (#3090) (#3096)
(cherry picked from commit 8cd4d47) Signed-off-by: solonovamax <solonovamax@12oclockpoint.com> Co-authored-by: solo <solonovamax@12oclockpoint.com>
1 parent 217e7a7 commit 3a053fb

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

rclcpp_components/src/component_container_mt.cpp

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

26-
auto exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
27-
auto node = std::make_shared<rclcpp_components::ComponentManager>();
26+
rclcpp::executors::MultiThreadedExecutor::SharedPtr exec = nullptr;
27+
const auto node = std::make_shared<rclcpp_components::ComponentManager>();
2828
if (node->has_parameter("thread_num")) {
2929
const auto thread_num = node->get_parameter("thread_num").as_int();
3030
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>(
3131
rclcpp::ExecutorOptions{}, thread_num);
32-
node->set_executor(exec);
3332
} else {
34-
node->set_executor(exec);
33+
exec = std::make_shared<rclcpp::executors::MultiThreadedExecutor>();
3534
}
35+
node->set_executor(exec);
3636
exec->add_node(node);
3737
exec->spin();
3838
}

0 commit comments

Comments
 (0)