博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多线程生产者和消费者
阅读量:4154 次
发布时间:2019-05-25

本文共 522 字,大约阅读时间需要 1 分钟。

#include 
#include
#include
#include
#include
#include
using namespace std;const int ConsumerNum = 3;const int PruducterNum = 2;const int M = 20;//缓存区大小int in = 0;int out = 0;int buff[M] = {0};sem_t empty_sem;//表示空位的数量sem_t full_sem;//产品的数量pthread_mutex_t mutex;//线程在读取或产生时,都应该加锁int i=0;//产品Idvoid *product(void *){ while (true) { //sleep(1); sem_wait(&empty_sem);//空位数减1,已经把这个位置站住了,其他线程只能访问剩余位置 pthread_mutex_lock(&mutex); cout<<"producter "<
<<" produce "<
<

转载地址:http://useti.baihongyu.com/

你可能感兴趣的文章
Tomcat配置域名、ip访问及解决80端口冲突
查看>>
详解Java反射机制
查看>>
网站优化之Tomcat启用Gzip压缩
查看>>
Linux下mysql的彻底卸载
查看>>
python爬虫解决极验验证码问题
查看>>
使用JS将table表格导出为excel
查看>>
java调用阿里云短信服务接口
查看>>
idea的个性配置
查看>>
Java获取访问者Ip并限制Ip访问页面
查看>>
Java读取src下配置文件的问题
查看>>
网页加载时waiting(TTFB)时间过长的问题解决
查看>>
Java时间日期相关工具类
查看>>
JS使用OSS上传文件遇到的一些问题
查看>>
个人博客写了两年
查看>>
博客添加评论功能
查看>>
VMware Ubuntu安装教程(详细过程)
查看>>
Java新手的通病
查看>>
Java虚拟机知识汇总,Jvm面试必问
查看>>
LifecycleProcessor not initialized - call ‘refresh‘ before invoking lifecycl
查看>>
js实现选中div内容并复制到剪切板
查看>>