目录
1.多线程概念
1.1主线程
1.2 线程内部原理图
1.3多线程的共享与独有
1.4 多线程优缺点
2线程控制
2.1线程创建
2.1.1接口
2.1.2代码演示
2.2线程终止
2.2.1接口
2.2.2代码演示
2.2.3线程的僵尸状态模拟
2.3线程等待
2.3.1接口
2.3.2代码演示
#include<stdio.h>
#include<unistd.h>
#include<pthread.h>
void* mythread(void* arg){
printf("i am workthread!\n");
}
int main(){
//创建线程
pthread_t tid;
int ret= pthread_create(&tid,NULL,mythread,NULL);
if(ret<0){
perror("pthread_create");
return 0;
}
pthread_join(tid,NULL);
return 0;
}
2.4线程分离
2.3.1接口
2.3.2代码演示
void* mythread(void* arg){
pthred_detach(pthread_self());
printf("i am work thread\n");
}