multi-threaded spinner
Application Scenario
Suppose that we have two callbacks (talker1 and talker2) running at 1Hz in the same ros node. The talker2 callback can be blocked if the talker1 callback takes more than 1s. Because
ros::spin()
is single-threaded.Note: this issue only happens with roscpp. The rospy spinner is already multi-threaded, so you wonβt be able to reproduce this issue if you translate the cpp subscriber node to Python.
Solution One: MultiThreadedSpinner
Blocking method. Simply just increase the number of threads to process callback queues.
Solution Two: AsyncSpinner
Non-blocking method. Try to get each callback a thread if available.
References: http://wiki.ros.org/roscpp/Overview/Callbacks%20and%20Spinning; https://roboticsbackend.com/ros-asyncspinner-example; https://levelup.gitconnected.com/ros-spinning-threading-queuing-aac9c0a793f
Last updated