本文共 556 字,大约阅读时间需要 1 分钟。
线程退出函数
pthread_exit 线程退出注意事项: 在线程中使用pthread_exit 在线程中使用return(主控线程return代表退出进程) exit代表退出整个进程pthread_exit.c
#include#include #include #include void* thr(void *arg){ printf("I am a thread! pid=%d,tid=%lu\n",getpid(),pthread_self()); //return NULL; pthread_exit(NULL); exit(1);}int main(){ pthread_t tid; pthread_create(&tid,NULL,thr,NULL); printf("I am a main thread! pid=%d,tid=%lu\n",getpid(),pthread_self()); sleep(3); printf("I will out\n"); pthread_exit(NULL); return 0;}
转载地址:http://lrwh.baihongyu.com/