Rosanswers logo


I am trying to understand different options to use multi threading with ROS. I found different things :

  • Use MT nodelet interface (with getMTNodeHandle())
  • Use MultiThreadedSpinner or AsyncSpinner
  • Use boost::thread

I have few questions about that.

  • In a general case, what is the difference between using MT nodelet interface and MultiThreadedSpinner ? because both distribute the callbacks in different threads.
  • What are the advantages of using MT nodelet interface ?
  • Would you choose between each of these methods according to each case or can we combine boost::thread and MT nodelet interface for example ?
  • Is there some explanations about effects (in performance for example) of all these methods ?
  • Is it better to use pThread or Boost.Thread ?

Thanks for help, hope someone will be able to help me clarify that.


Originally posted by CarolineQ on ROS Answers with karma: 395 on 2013-06-05

Post score: 4


1 Answer 1


Rosanswers logo

If you're in a nodelet use the multi threaded nodelet interface.
If you're not use the Asynchronous spinner.

The nodelet interface will only work if you're inside a nodelet manager as a nodelet.

You can add your own threads on top of the callback threads in either case. If you do you are in charge of cleaning up correctly.

For portability Boost Thread is recommended over pthreads.

In most cases there will be no performance difference, unless you are doing something very exotic. And if you're doing that very exotic thing you will know the performance differences. The most common case is running a single threaded process.

Originally posted by tfoote with karma: 58457 on 2013-06-12

This answer was ACCEPTED on the original site

Post score: 0

Original comments

Comment by CarolineQ on 2013-06-12:
Thanks a lot for your answer. It is very useful. One last question, how do you decide if you have to use nodelets instead of nodes ? Is it only when you use heavy messages ?

Comment by tfoote on 2013-06-12:
Nodelets are designed to enable dynamically loading code into the same process for efficiency. However, those efficiency gains come at the cost of no process isolation, and not controlling the whole process.

Comment by tfoote on 2013-06-12:
If you're not doing something which is going to be processor intensive it's not worth much computationally. The nodelets do provide a simpler programming paradigm once you learn how to use them.

Comment by CarolineQ on 2013-06-12:
Thanks ! It's clearer now !


Your Answer

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