网站的c4d动画是怎么做的,广告公司网站建设的定位,中小型网站站内搜索实现,网站开发交易网站进程终止时exit()函数#xff0c;那么线程终止的是什么呢#xff1f; 线程终止的三种情况#xff1a; 线程只是从启动函数中返回#xff0c;返回的是线程的退出码#xff1b;线程可以被同一进程中的其他线程取消#xff1b;线程调用pthread_exit。/***
exit.c
***/
#incl… 进程终止时exit()函数那么线程终止的是什么呢 线程终止的三种情况 线程只是从启动函数中返回返回的是线程的退出码线程可以被同一进程中的其他线程取消线程调用pthread_exit。 /***
exit.c
***/
#includestdio.h
#includestring.h
#includestdlib.h
#includeerrno.h
#includepthread.hvoid *func(void *arg)
{int i 0;while(1){if(10 i){int *p (int *)malloc(sizeof(int));*p 11;pthread_exit(p);}printf(fun run %d \n,i);sleep(1);}return NULL;
}int main()
{pthread_t t1,t2;int err pthread_create(t1,NULL,func,NULL);if( 0 ! err){printf(thread_create failed : %s\n,strerror(errno));} else {printf(thread_create success\n);}void *p NULL;pthread_join(t1,p);printf(thread exit : code %d\n,*(int *)p);return EXIT_SUCCESS;
} 运行结果 exbotubuntu:~/wangqinghe/thread/20190729$ gcc exit.c -o exit -lpthread exbotubuntu:~/wangqinghe/thread/20190729$ ./exit thread_create success fun run 0 fun run 1 fun run 2 fun run 3 fun run 4 fun run 5 fun run 6 fun run 7 fun run 8 fun run 9 thread exit : code 11 void pthread_exit(void *arg) pthread_exit函数的参数就跟正常线程结束return的使用时一样的都会被等待它结束的主线程获取到。 转载于:https://www.cnblogs.com/wanghao-boke/p/11262731.html