我有一些代码,大致如下:
pthread_create(thread_timeout, NULL, handleTimeOut, NULL);
void handleTimeOut()
{
/*...*/
pthread_cancel(thread_timeout);
/*...*/
}
但是我注意到pthread的手册中取消必须由其他线程使用。我试图使用pthread_exit()函数代替,但这个线程又再次挂起...
如何正确处理线程终止?如果handleTimeOut()函数没有特殊的pthread函数而只是结束,它会成功终止吗?