【发布时间】:2012-10-23 14:24:36
【问题描述】:
我面临一个与 pthread_cancel 相关的问题。请看下面的代码:
void* func(void *arg)
{
while(1)
{
sleep(2);
}
}
#include<stdlib.h>
#include <stdio.h>
#include <pthread.h>
int main()
{
void *status;
pthread_t thr_Var;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL);
pthread_create(&thr_Var,NULL,func,NULL);
pthread_cancel(thr_Var);
pthread_join(thr_Var,&status);
return 0;
}
我怀疑即使我禁用了取消状态,pthread_cancel 仍在工作并且线程正在终止。 任何帮助将不胜感激
【问题讨论】: