catching SIGINT in a nodelet thread
Hello everyone!
I have a thread, that is launched by a Nodelet that monitors messages of published topics (topics are published by another Node). According to this answer, the expected way to close a thread is to terminate it in a destructor of a Nodelet (which I am doing).
However, my Nodelet, upon termination via Ctrl+C, would shutdown later than the other Node (that publishes messages). This causes the thread of Nodelet to react to the fact, that no messages arrive.
I tried to use signal(SIGINT, handler)
in the thread, to catch the SIGINT and only stop the thread.
However, then the Nodelet manager won't terminate and would wait until a message Escalating to SIGTERM
.
How to make sure that the thread would get terminated first? How to make sure that Nodelets are terminated smoothly, without a SIGTERM?