ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For multithreaded callback queues of ROS have a look at this:

http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

Note that if you uses MultiThreaded or AsynchSpinners your callbacks might be called in parallel, i. e. you will need mutexes and condition_variables to properly sync your callbacks and avoid race conditions.

For multithreaded callback queues of ROS have a look at this:

http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning

Note that if you uses MultiThreaded or AsynchSpinners your callbacks might be called in parallel, i. e. you will need mutexes and condition_variables to properly sync your callbacks and avoid race conditions.

Edit:

Includes:

#include <ros/ros.h>
#include <ros/callback_queue.h>

Set up like this:

// create instances
ros::NodeHandle my_nh;
ros::CallbackQueue my_queue;
ros::AsyncSpinner my_spinner( 2 /*number of threads*/, &my_queue /* spinner exclusively for my_queue */);

// bind the queue to the node handle
my_nh.setCallbackQueue( &my_queue );

// now advertise/subscribe using my_nh
ros::Subscriber my_subscriber_foo = my_nh.subscribe( "foo", 1, onFooReceived );
ros::Subscriber my_subscriber_bar = my_nh.subscribe( "bar", 1, onBarReceived );

// now start the spinner
my_spinner.start();

Your callbacks onFooReceived and onBackReceived can now be executed in parallel, if messages arrive such that this is appropriate...