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

how are threads used to service callbacks in nodelets? [closed]

asked 2014-06-03 10:07:11 -0500

Matias gravatar image

I have several nodelets, each subscribes to different messages (using the single threaded node handle). However, I realized one of my nodes, which subscribes to images and to odometry messages, and which takes long to process a single image (and therefore looses odometry messages in the mean time). Another nodelet, also subscribed to odometry messages, receives all of them while the first nodelet is busy with an image. So I understand the image callback of the first nodelet is being serviced by a different thread than of the second nodelet. However, inside a single nodelet, it appears that servicing one callback blocks the other callback.

I really don't understand how does the nodelet manager uses threads to service callbacks both between nodelets and inside the same nodelet.

  • What would be the difference between using the single-threaded and multi-threaded node handles of the nodelet manager?
  • Does the nodelet manager have a single queue which receives all messages that nodelets subscribes to, and then uses the worker threads to service these? Or does each nodelet have a separate callback queue?
    • What I should I do if I only want to process two specific callbacks in parallel (after making them thread-safe) of a single nodelet, but still call any other callback (from this nodelet or others) serially?
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Matias
close date 2015-06-26 17:22:25.330580

Comments

No answers yet? I have the same doubts.

McMurdo gravatar image McMurdo  ( 2014-07-18 04:48:09 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2014-08-13 17:10:39 -0500

tfoote gravatar image

The threading model is documented at: http://wiki.ros.org/nodelet#Threading...

It's built upon the standard ROS threading, documented at: http://wiki.ros.org/roscpp/Overview/C...

The multi-threaded node handle has the shared thread pool also shares a callback queue across all multi threaded node handles in the process.

The single threaded node handle has a custom callback queue with a single thread shared across all single threaded node handles in the process.

If you want very specific behavior I suggest setting up your own callback queues and threads within the nodelet.

edit flag offensive delete link more

Comments

So, any two callbacks associated to the MT handle could be executed in parallel, right? And will callbacks associated to the ST handle will also be run in parallel to MT handle callbacks? In other words, I have to ensure thread safety between any MT callback and any other callback (be it MT or ST).

Matias gravatar image Matias  ( 2014-08-14 08:24:22 -0500 )edit

That's correct.

tfoote gravatar image tfoote  ( 2014-08-14 11:08:21 -0500 )edit
0

answered 2014-08-13 13:02:34 -0500

esteve gravatar image

In your case, you could either:

Both approaches are fine, though with the first one you will be responsible for managing the thread you spawn, whereas with the second one it's all handled by the nodelet manager threadpool

edit flag offensive delete link more

Comments

I understand the options but not what is the impact of using the MT handle. Please see my questions in the items above.

Matias gravatar image Matias  ( 2014-08-13 13:32:26 -0500 )edit

Question Tools

Stats

Asked: 2014-06-03 10:07:11 -0500

Seen: 6,474 times

Last updated: Aug 13 '14