pthread
来源:互联网 发布:南风知我意 吹梦到西洲 编辑:程序博客网 时间:2024/06/06 16:29
1.pthread_create(pthread_t thread,const pthread_attr_t *attr,void (start_routine) (void),void *arg);
线程id,线程属性,线程创建之后执行的函数,start_routine的函数的传参
void (*start_routine) (void) 是函数指针,void* 是函数返回值类型,start_routine是函数指针名,void 是函数参数
2.pthread_join(pthread_t thread,void **retval); 阻塞,等待thread线程结束,才继续往下执行
start_routine退出时返回的参数,就是retval的内容
3.pthread__exit(2);//自杀
pthread_cancel(threadid) //他杀
-
pthread_mutex_t mutex;
pthread_mutex_init(&mutex,NULL);//初始化互斥锁
pthread_mutex_lock(&mutex);//加锁
pthread_mutex_unlock(&mutex);//解锁
pthread_mutex_destory(&mutex);//销毁互斥锁
5, pthread_cond_t has_product;条件变量
pthread_cond_init(&has_product,NULL);
pthread_cond_signal(&has_product); 通知
pthread_cond_wait(&has_product,&mutex); 等待
pthread_cond_signal函数的作用是发送一个信号给另外一个正在处于阻塞等待状态的线程,使其脱离阻塞状态,继续执行.如果没有线程处在阻塞等待状态,pthread_cond_signal也会成功返回pthread_cond_wait用于阻塞当前线程,等待别的线程使用 pthread_cond_signal() 或pthread_cond_broadcast来唤醒它,一进入wait状态就会自动release mutex。当其他线程通过 pthread_cond_signal() 或pthread_cond_broadcast ,把该线程唤醒,使 pthread_cond_wait()通过(返回)时,该线程又自动获得该mutex 。
阅读全文
0 0
- Pthread
- pthread
- pthread
- PThread
- pthread
- pthread
- pthread
- pthread
- pthread
- pthread
- pthread
- pthread
- pthread
- pthread
- Pthread
- pthread
- pthread
- Pthread
- 安装vue-cli脚手架提示Error: spawn npm ENOENT的解决方式
- 临时
- Android城市索引含定位和热门城市(悬浮块+右侧字母索引)
- 栈的理解 IAR/MDK修改stack/heap
- 3d_coordinates 测量世界坐标中的倾斜物体
- pthread
- deeplearning 发展历程
- vs对文本的检测和读取
- python 按字典value排序以及按list中字典的某个key的value排序
- 正则表达式
- Redis-Cluster集群搭建及配置
- stl2xml.py 代码实现了stl格式转化为xml格式
- /bin/bash^M: bad interpreter: No such file or directory问题
- Leetcode: 698. Partition to K Equal Sum Subsets