1、linux创建子线程的思路
1) 在主线程中,调用pthread_create创建子线程。
2) 子线程函数,打印输出。
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_create创建子线程,子线程函数打印输出
备注:pthread_create成功返回0,失败返回错误码。
命令:
[root]#touch main.cpp
[root]#vi main.cpp


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

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