#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
pthread_t id;
void *thread_func(void *args)
{
printf("child-- start\n");
pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,NULL);
while(1){
;
};
printf(":-D thread have been killed \n");
}
int main(int argc, char const *argv[])
{
int ret;
ret=pthread_create(&id,NULL,(void *)thread_func,NULL);
sleep(1);
printf("main~~~~~~start to cancel!/(ㄒoㄒ)/~~\n");
pthread_cancel(id);
pthread_join(id,NULL);
printf("bye bye\n");
return 0;
}
如何异步取消一个线程
最新推荐文章于 2024-10-30 10:32:09 发布