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

Revision history [back]

The answer depends on whether you are using roscpp or rospy. It seems you are using roscpp because you mentioned std::vector. If you are simply using ros::spin or ros::spinOnce there is only a single thread handling callbacks so there should be no need for any sort of mutex.

If you'd like to use a multi-threaded approach to processing your callbacks, roscpp includes the ros::MultiThreadedSpinner and ros::AsyncSpinner. If using one of these spinners, you should take care to prevent access collisions.

This information was pulled from the Callbacks and Spinning roscpp Overview page.

The answer depends on whether you are using roscpp or rospy. It seems you are using roscpp because you mentioned std::vector. If you are simply using ros::spin or ros::spinOnce there is only a single thread handling callbacks so there should be no need for any sort of mutex.

If you'd like to use a multi-threaded approach to processing your callbacks, roscpp includes the ros::MultiThreadedSpinner and ros::AsyncSpinner. If using one of these spinners, you should take care to prevent access collisions.

This information was pulled from the Callbacks and Spinning roscpp Overview page.

EDIT

IMO, it can be a bit difficult to find documentation on the rospy threading model (and I'm apparently too lazy to write a wiki page about it), but this ROS answers post has a clear and concise description.