I am trying to stop two threads from within a while loop but it doesn't stop on the Ctrl+C (SIGINT).How do I terminate the threads on receiving Ctrl+C from CLI? Would an AsyncSpinner
help me here? I do not understand the syntax implementation of AsyncSpinner
, specifically how to assign a method to a thread spun by it (as I have been able to do with std::threads
below).
void Listener::spin(int sockfd){
int n;
sock_fd_ = sockfd;
ros::Rate loop_rate(MESSAGE_FREQ); // set the rate as defined in the macro MESSAGE_FREQ
while(ros::ok) {
loop_rate.sleep();
std::thread t_write(&Listener::getMessageValue, this); //writes data onto tcp socket
std::thread t_read(&Listener::readBuffer, this); // reads data from tcp socket
t_write.join();
t_read.join();
ros::spinOnce();
}
n = close(sock_fd_);
}
This is being called in the main like this:
int main(int argc, char *argv[]) {
....
listener.spin(sockfd);
return 0;
}
Originally posted by curi_ROS on ROS Answers with karma: 166 on 2019-02-19
Post score: 0