1、等待子线程退出的思路
1) 主线程中,使用pthread_create创建子线程
2) 主线程中,使用pthread_join等待子线程退出
2、pthread_create的语法形式
类库:#include <pthread.h>
原型:
int pthread_create(pthread_t * thread, const pthread_attr_t * attr,
void * (*start_routine)(void*)), void * arg);
参数:
thread -> 线程ID
attr -> 线程属性
start_routine -> 线程函数
arg -> 线程入参
3、pthread_join的语法形式
类库:#include <pthread.h>
原型:int pthread_join(pthread_t thread, void **retval);
参数:
thread -> 线程ID
retval -> 线程推出返回值
4、创建子线程,等待子线程退出
命令:
[root]#touch main.cpp
[root]#vi main.cpp


5、编译
备注:编译需要链接pthread库。

6、运行
备注:符合预期,测试OK!
