pthread_cancel怎么等一个还未执行的线程结束?
static pthread_t tid = 0;void *SubThread(void *arg)
{
printf("enter thread\n");
while (1)
{
// do something;
pthread_testcancel();
}
printf("exit thread\n");
}
void FirstCall(void)
{
pthread_create(&tid, NULL, SubThread, NULL);
}
void SecondCall(void)
{
int ret = pthread_cancel(tid);
// 要等子线程结束
pthread_join(tid, NULL); // 若SubThread还未执行,会阻死了
}
一般情况下能使用,当出现异常时调用FirstCall()后很快就调SecondCall();然后就阻死了。
该怎么解决,请各位指教下!
页:
[1]