0
$\begingroup$

Rosanswers logo

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.


Originally posted by maartenvds on ROS Answers with karma: 1 on 2018-02-23

Post score: 0


Original comments

Comment by rt_ros on 2020-09-23:
Hi, incase if you had found the ans, it will useful if you could share it.

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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.


Originally posted by gvdhoorn with karma: 86574 on 2021-10-15

This answer was ACCEPTED on the original site

Post score: 1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.