ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ros::init() running multiple threads?

asked 2018-02-23 06:06:29 -0500

maartenvds gravatar image

As a ros user you probably shouldn't know about the internals of ros::init(), but looking at htop when running a simple ros node shows at least 5 threads on my linux machine (kinetic release). If I comment out ros::init(argc, argv, "my_node") (then it's probably not a ros node anymore) I see only 1 thread. I guess this is normal behavior but I was just wondering what all these threads are for? And is the thread count always 5 or depending on something?

I want to be able to count how many threads my program is using excluding ros threads.

edit retag flag offensive close merge delete


Hi, incase if you had found the ans, it will useful if you could share it.

rt_ros gravatar image rt_ros  ( 2020-09-23 07:22:00 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-15 02:23:20 -0500

gvdhoorn gravatar image

updated 2021-10-15 02:24:16 -0500

As part of initialising ROS using ros::init(..), roscpp starts a couple of threads which run in the background of your application.

Those threads are responsible for managing event queues, subscriptions, publications, sockets, interactions with roscore, etc, etc.

And is the thread count always 5 or depending on something?

I haven't verified this, but it's likely this number can grow based on whether you use singlethreaded or multithreaded spinners, create additional callback queues (with their own spinners), etc.

The number you've observed is the default for a single node with no special initialisation.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-02-23 06:06:29 -0500

Seen: 422 times

Last updated: Oct 15 '21