I am working on ROS environment, and trying to read CANBUS on a parallel thread. I initialized canbus in main thread because I want to make sure that CAN cables are connected. By initializing, I mean setsockopt(), ioctl(), bind() to configure the socket.
void readCanbus(int soktId) {
while(true)
int nbytes = read(soktId, ...);
}
int main() {
int soktId;
someSocketSetupFn(soktId);
std::thread t(readCanbus, soktId);
t.join();
return 0;
}
Problem: If there is no incoming CAN messages, read() is blocked. Ctrl+C doesn't terminate the C++11 Program.
How can I make the read() terminate and so the whole program?
Terminate thread c++11 blocked on read This post proposed a solution for POSIX. I am working on ubuntu16.04.
Aucun commentaire:
Enregistrer un commentaire