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

One Thread Per Subscriber

asked 2016-02-16 01:59:21 -0500

solb22 gravatar image

updated 2016-02-16 02:00:21 -0500

I'm using roscpp, and I am programmatically creating a bunch of subscriber callbacks (using ShapeShifter). Each callback is not computationally expensive, but I'm measuring the difference between the published time in the header, and the received time. As such, the first line of my callback defines the received time.

So having a single threaded model isn't great, because one subscriber callback will block another callback, and increase its lag time.

Ideally I'd like to create one thread per subscriber. I can't use a custom callback queue, because these are not called by ros::spin.

So what is the most idiomatic way to have each subscriber run on its own thread?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-02-16 02:49:40 -0500

gvdhoorn gravatar image

updated 2016-02-16 02:52:17 -0500

Does ros::MultiThreadedSpinner not already do what you describe? See roscpp - Overview - Callbacks and Spinning.


Edit: you might also be interested in the topic statistics support added in Indigo. See Topics - Topic statistics and rosprofiler.

edit flag offensive delete link more

Comments

Hm, I guess it does, is there a limit to the number of thread I can pass to that? The documentation made it look like I was limited to the number of cores on my machine. I was actually looking at ros::AsyncSpinner

solb22 gravatar image solb22  ( 2016-02-16 03:09:35 -0500 )edit

Both the wiki page and the API documentation state:

You can specify a number of threads in its constructor, but if unspecified (or set to 0), it will use a thread for each CPU core.

Num cpus is only default

gvdhoorn gravatar image gvdhoorn  ( 2016-02-16 03:26:35 -0500 )edit

Same applies to AsyncSpinner.

gvdhoorn gravatar image gvdhoorn  ( 2016-02-16 03:33:25 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2016-02-16 01:59:21 -0500

Seen: 720 times

Last updated: Feb 16 '16