Ask Your Question

Multiple Threads in Single ROS Node

asked 2011-06-20 02:28:08 -0500

SyllogismRXS gravatar image

updated 2014-01-28 17:09:53 -0500

ngrennan gravatar image

What is the preferred threading library to use when trying to write a ROS node with multiple threads? Boost::Thread ? Posix ? Pthreads ?

Are there any issues with callback functions when multiple threads are used?

The reason I want to use multiple threads in a single node instead of writing multiple nodes is that I am trying to integrated ROS with another publish and subscribe system called MOOS, which is used heavily in the underwater robotics community. (Found here: Unfortunately, the MOOS architecture relies upon the user calling a blocking function that sits and spins in a loop (similar to ROS, but all the initial logic is tied up in that one function as well). I want to run that blocking function in its own separate loop, grabbing data from the MOOS system and then publishing it to the ROS side.

Any tips?

edit retag flag offensive close merge delete


ROS package posest in vslam uses Intel TBB, but from my experience TBB aims at parallelization of computationally expensive tasks, so you're probably looking for sth. else here.
Julius gravatar image Julius  ( 2011-06-21 01:03:24 -0500 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2011-06-21 06:13:16 -0500

bhaskara gravatar image

updated 2011-06-21 20:52:48 -0500

Boost::threads is commonly used, but the others should work as well. Info on callbacks in roscpp is at For your case, spinning off a thread that calls the moos loop, then calling ros::spin in the main thread, sounds like it will work.

edit flag offensive delete link more


This is how I ended up implementing my MOOS / ROS node and it worked well.
SyllogismRXS gravatar image SyllogismRXS  ( 2011-06-24 04:21:30 -0500 )edit

Hello,I run spin() in boost::thread,but it's also block my GUI?Thanks for your help.

zzzZuo gravatar image zzzZuo  ( 2015-12-30 20:45:14 -0500 )edit

answered 2011-06-20 15:41:24 -0500

joq gravatar image

I've mostly used boost::thread, because many other ROS components use it. Works fine. I also like the boost::mutex::scoped_lock.

edit flag offensive delete link more


I use spin() in boost::thread,but it's also block my GUI,thanks for your help.

zzzZuo gravatar image zzzZuo  ( 2015-12-30 20:43:21 -0500 )edit

answered 2011-06-21 20:51:46 -0500

For my last project I used qt threads and liked them. As for your problem, I also had to run the ros spinning in a seperate thread, since qt uses its own spinning for signals and slots communication (which btw can be used for calls across threads). The implementation is in the qtros class

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-06-20 02:28:08 -0500

Seen: 11,556 times

Last updated: Jun 21 '11