1使用pthread库创建线程
背景
本章要求读者已经理解“线程”“互斥”等 相关概念
在Linux下,使用pthread库来创建和操作线程。
pthread库是Linux系统自带的一个库。
使用pthread库
- Makefile
LDFLAGS += ‐lpthread - 头文件
#include <unistd.h>
#include <pthread.h>
uni: unix
std: standard
创建一个线程
使用pthread_create函数来创建线程
① 定义线程的主函数
void* Thread_Main(void* context)
② 调用pthead_create
pthread_t handle;
pthread_create(&handle, // 线程句柄
NULL, // 忽略