C语音的线程基本函数使用
线程常用基本函数:
1.pthread_create() 创建线程
2.pthread_exit() 退出当前线程
3 pthread_join() 等待其他线程结束
4.pthread_self() 自身线程ID号
5.pthread_cancel() 停止其他线程
6.pthread_detach() 分离某个线程
线程使用需要导入对应头文件
#include <pthread.h>
pthread_create() 创建线程
函数原型:
/**
* @brief 创建一个线程
* @param th 线程ID
* @param attr 线程属性,通常使用NULL
* @param func 线程函数入口
* @param arg 线程函数传参
* @return int 创建成功返回0,失败返回错误代码
*/
int pthread_create(pthread_t *th,
const pthread_attr_t *attr,
void *(* func)(void *),
void *arg);
pthread_exit() 退出当前线程
函数原型: