I am sure this is documented somewhere but this is an important question that would be very nice to put to rest as far as locking requirements on data structures in a given node.
If ROS deals with this issue in a certain way (I doubt it but wanted to ask) then I can have less clumsy code by avoiding all the pitfalls one can hit with locking.
In a multi-node ROS system with lots of topics consider one of the ros nodes that has a few callbacks that listen to topics but only one node in this process.
If I populate a queue of data structures from a callback, is the pulling of data from these same data structures safe without a lock?
To say another way: Is a process global data structure (C++ queue or just structure) used in main() for the ROS node safe to use data that can be modified in those callbacks?
If a callback for subscription to a topic can happen on ANY linux context switch or any ROS call such as ROS_INFO or ros::sleep() then my answer is a 'yes a lock is required'.
In the 'real world' the answer would be of course you have to lock it but ROS is it's own environment and both main() and callbacks are a ROS context on top of linux.
this issue may be a FEATURE of ROS and I want to know if it is or most likely is not a feature.
Since ROS is a single process I wonder if callbacks to listen to topics are asynchronous and can be done from a (thread) context switch out of the ROS main() loop OR if those callbacks are ONLY managed when you call something like ros::spinOnce().
I have been assuming my locks are requred, just asking.
Thanks,
Mark Johnston