perror("setcancelstate");
}
if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL) != 0)
{
perror("setcancelsype");
}
while(1)
{
sleep(1);
printf("thread_a\n");
pthread_testcancel();
}
}
void *thread_b(void *arg)
{
if(pthread_setcancelstate(PTHREAD_CANCEL_DISABLE,NULL) != 0)
{
perror("setcancelstate");
}
while(1)
{
sleep(1);
printf("thread_b\n");
pthread_testcancel();
}
}
void *thread_c(void *arg)
{
if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL) != 0)
{
perror("setcancelstate");
}
if(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL) != 0)
{
perror("setcancelsype");
}
while(1)
{
sleep(1);
printf("thread_c\n");
pthread_testcancel();
}
}
int main(int argc, char **argv)
{
pthread_t tid_a,tid_b,tid_c;
int err;
err = pthread_create(&tid_a,NULL,thread_a,(void *)&tid_a);
if(err < 0)
{
perror("pthread_create thread_a");
}
printf("create tid_a = %u\n",tid_a);
err = pthread_create(&tid_b,NULL,thread_b,(void *)&tid_b);
if(err < 0)
{
perror("pthread_create thread_b");
}