ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

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

Comments

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
1

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

Question Tools

3 followers

Stats

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

Seen: 662 times

Last updated: Oct 15 '21