ros::ok() within pthread
I am have a couple of threads that run in a node. The threads have a while(ros::ok()) infinite loop inside. The problem is that when I Ctrl-C my program, it has to escalate to a SIGTERM because the ros::ok() variable never goes false. I also tried the ros::isShuttingDown() variable and this never goes true.
How should I handle the pthreads so that they exit when the rest of the program exits?
I launch threads with:
pthread_t thread1
pthread_create(&thread1,NULL,thread1Function,NULL);
My thread function looks something like this:
void *thread1Function(void *obj)
{
ros::Rate loop_rate(1);
while(ros::ok())
{
//Do stuff
loop_rate.sleep();
ros::spinOnce();
}
pthread_exit(NULL);
}
The loop never exits.