Ask Your Question
4

Multi threading [closed]

asked 2013-06-05 22:39:33 -0600

CarolineQ gravatar image

updated 2013-06-06 21:38:31 -0600

Hi,

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.

Caroline

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by CarolineQ
close date 2013-06-12 22:22:22

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-06-12 12:31:31 -0600

tfoote gravatar image

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.

edit flag offensive delete link more

Comments

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 ?

CarolineQ gravatar imageCarolineQ ( 2013-06-12 21:25:41 -0600 )edit

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.

tfoote gravatar imagetfoote ( 2013-06-12 21:40:22 -0600 )edit

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.

tfoote gravatar imagetfoote ( 2013-06-12 21:41:23 -0600 )edit

Thanks ! It's clearer now !

CarolineQ gravatar imageCarolineQ ( 2013-06-12 22:20:33 -0600 )edit

Question Tools

Stats

Asked: 2013-06-05 22:39:33 -0600

Seen: 1,067 times

Last updated: Jun 12 '13