线程条件变量
来源:互联网 发布:淘宝手机评价管理登录 编辑:程序博客网 时间:2024/06/06 15:54
范例如下:
#include<stdio.h>
#include<unistd.h>#include<pthread.h>
pthread_mutex_t mutex;
pthread_cond_t cond;
void * thread1(void *arg){
pthread_cleanup_push(pthread_mutex_unlock,&mutex);
while(1)
{
printf("thread1 is running\n");
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
printf("thread1 applied the condition\n");
pthread_mutex_unlock(&mutex);
sleep(4);
}
pthread_cleanup_pop(0);
}
void *thread2(void *arg)
{
while(1){
printf("thread2 is running\n");
pthread_mutex_lock(&mutex);
pthread_cond_wait(&cond,&mutex);
printf("thread2 applied the condition\n");
pthread_mutex_unlock(&mutex);
sleep(1);
}
}
int main(void){
pthread_t tid1,tid2;
printf("condition variable study!\n");
pthread_mutex_init(&mutex,NULL);
pthread_cond_init(&cond,NULL);
pthread_create(&tid1,NULL,(void*)thread1,NULL);
pthread_create(&tid2,NULL,(void*)thread2,NULL);
do{
pthread_cond_signal(&cond);
}while(1);
sleep(50);
pthread_exit(0);
}
0 0
- 线程同步-条件变量
- 线程条件变量详解
- POSIX线程:条件变量
- pthread_cond 线程条件变量
- 线程 条件变量
- 线程条件变量pthread_cond_t
- 线程条件变量
- POSIX线程:条件变量
- 线程同步条件变量
- 线程-条件变量
- 线程信号条件变量
- coding---线程条件变量
- linux 线程 条件变量
- 线程条件变量pthread_cond_t
- 线程条件变量pthread_cond_t
- 线程3:条件变量
- 线程条件变量pthread_cond_t
- 线程条件变量pthread_cond_t
- Android开发_屏幕亮度调节
- bootstrap简单的页面Demo1
- BeanUtils基本简介
- WiFi QoS in Windows
- 欢迎使用CSDN-markdown编辑器
- 线程条件变量
- lua解析脚本过程中的关键数据结构介绍
- bootstrapbootstrap按钮bootstrap图像
- 包含min函数的栈
- JS作用域、链学习笔记
- Convert Sorted List to Binary Search Tree
- bootstrap搜索图标的使用
- 《JavaScript语言精粹》学习笔记
- POJ2001Trie树的运用