multi-threaded spinner
Application Scenario
Solution One: MultiThreadedSpinner
ros::MultiThreadedSpinner spinner(4); // Use 4 threads; or 0 to use all threads
spinner.spin(); // spin() will not return until the node has been shutdownSolution Two: AsyncSpinner
int main(int argc, char **argv) {
ros::init(argc, argv, "talker_subscribers");
ros::NodeHandle nh;
ros::AsyncSpinner spinner(0); // 0 means max number of threads available
spinner.start(); // start the AsyncSpinner asynchronously (non-blocking)
ros::Subscriber counter1_sub = nh.subscribe("talker1", 10, callbackTalker1);
ros::Subscriber counter2_sub = nh.subscribe("talker2", 10, callbackTalker2);
ros::waitForShutdown(); // block the program; wait for the node to be killed
// alternatively, you may have an infinite loop here to process some data
}Last updated