Linux--多线程之线程的创建和退出
2016-12-03 19:39
585 查看
#include "apue.h" /** 1.main函数的线程称为初始线程或主线程,主线程在main函数返回的时候,会导致 整个进程结束。可以在主线程中使用pthread_exit函数 退出主线程 如此, 进程会等待所有的线程结束时候才终止 */ struct person{ int age; char name[10]; }; void *thread_fun(void *person1){ //打印出当前线程的ID printf("fun thread id=%lu\n", pthread_self()); printf("age =%d name=%s \n",((struct person*)person1)->age,((struct person*)person1)->name); return NULL; } int main(){ pthread_t tid; int err; struct person per; per.age = 20; strcpy(per.name,"liu pan"); //创建线程 err = pthread_create(&tid,NULL,thread_fun,&per); if(err!=0){ perror(" fail to create thread "); return -1; } printf("success to create thread tid = %lu \n ",tid); //打印出当前线程的ID printf("main thread id=%lu\n", pthread_self()); //主线程退出 pthread_exit(NULL);//always succeeds }
相关文章推荐
- Linux下多线程编程__线程的创建pthread_create与退出pthread_exit,等待当前线程退出pthread_join,获取线程ID pthread_self
- Linux--多线程之线程的创建和退出
- linux多线程学习(二)——线程的创建和退出
- linux多线程学习(二)——线程的创建和退出
- linux线程创建、挂起、恢复、退出
- linux下的线程的创建退出及回收
- 【原创】《Linux高级程序设计》杨宗德著 - Linux多线程编程 - 线程退出与等待
- Window API (七)多线程的创建、退出、传递线程信息
- linux多线程学习(二)——线程的创建和退出
- 【原创】《Linux高级程序设计》杨宗德著 - Linux多线程编程 - 线程概念及创建线程
- 【原创】《Linux高级程序设计》杨宗德著 - Linux多线程编程 - 线程概念及创建线程 分类: Linux --- 应用程序设计 2014-11-19 17:31 82人阅读 评论(0) 收藏
- Linux多线程(二)(线程等待,退出)
- linux基础编程:多线程基础总结:线程创建 终止 线程同步/互斥量/条件变量/信号灯
- 【Linux学习】pthread_create主线程与创建的新线程之间退出关系
- 【Linux学习】pthread_create主线程与创建的新线程之间退出关系
- linux多线程编程1--线程的创建
- Linux编程练习 --多线程1--线程创建
- linux多线程学习(二)——线程的创建和退出
- 判断多线程是否退出,再创建这个线程。
- 【Linux学习】pthread_create主线程与创建的新线程之间退出关系