版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验报告 专业 软件工程 班级 学号 094、 094、 101、 103 姓名 陈璐、吴艺萍、崔旻、刘超群 实验日期: 2013 年 10月 17 日 课程 实验名称 报告退发(订正 生产者与消费者问题、 、重做) 读者一写者问题 一、实验目的 1. 实现生产者消费者问题模拟 2. 进一步掌握P, V如何解决同步和互斥问题 实验环境 1. 2. Windows 或 Linux 平台 Eclipse、Visual Studio 2005 或 GCC 实验内容、步骤和结果分析 实验内容: 实现生产者消费者问题模拟,显示每次添加和读取数据时缓冲区的状态, 生产者和消费者可用线程模拟。 1. 一个大
2、小为10的缓冲区,初始为空。 ID), 随机等待一段时间。 若缓冲区已满,等待消费者取走数据后再添加。 若缓冲区可以读取数据, 则示意进入消费过程 (打印出消费者ID ), 随机等待一段时间; 若缓冲区为空,等待生产者添加数据后再读取。 2. 五个生产者:若缓冲区可以加入数据,则示意进入生产过程(打印出生产者 往缓冲区添加数据, 3. 五个消费者: 从缓冲区读取数据, 四、讨论 (说明实验过程中遇到的问题及解决办法;未解决/需进一步研讨的问题或建议新实验方 法等) (请利用实验二中所给的各个版本信号量类来完成实验三。若选用Windows平台,要求 一定要选用这三个文件夹中的某个信号量类Sema
3、 phore来完成实验,否则实验报告视为 缺交;若选用Linux平台,也要求参照已给出的三个版本的Semaphore类的接口,先定 义一个Linux版本的C+类class Semaphore,并在该类基础上完成实验,提交实验报告 时请附上自定义的 Sema phore类。 读者一写 wmutex.VO; F F:M i c rosoft Vi sual Stu diol M yProj ec t 貞接作票统 I a b 30e b u g操作萦统 I a b - 752勺the students tAhlc 24G6urLtt ing the student S table 752峙readi
4、ng tlic student e table ing the student 3 tabla tlis student s tAhls 24G6ui*Lt t ing the student s tabls tbe students tab1b 246SuiLtt ing the student v tabla 24 9 七able ing tbe student 5 table 24GRuri.tC ing the student * s table the etudentF table ZGSwrittinff the studenttable 7524peat1 ing 752read
5、ing 7524peat1insf tbe tbe the tbe students student s student s student s table table table table 2468writtinsf the studenttable 7524readinsf tbe student s table 2468wpittinsf the studenttable 2468writtinsf the studenttable 752readinsf tbe student s table 752readinsf the student s table #inelude #ine
6、lude semaphore.h #inelude thread.h #inelude using namespacestd; Sema phore rmutex(1); Sema phore wmutex(1); int cou nt=0; un sig nedi nt WINA PI Reader( void *p) while(TRUE) rmutex. P(); cou nt+; rmutex.V(); if(eou nt = 1) wmutex. P(); cout GetCurre ntThreadIdO readi ng the stude nts tablee ndl; rmu
7、tex. P(); cou nt-; rmutex.V(); if(cou nt = 0) Slee p(ra ndO%1000); unsignedint WINAPI Writer( void *p) while(TRUE) wmutex .P(); cout GetCurre ntThreadld() writt ing the stude nts table e ndl; wmutex.V(); Slee p(ra ndO%1000); int mai n() HANDLE hThread2; hThread0 = startThread(Reader,NULL); hThread1
8、= startThread(Writer,NULL); :WaitForMult ip leObjects(2,hThread,TRUE,INFINITE); CloseHa ndle(hThread0); CloseHa ndle(hThread1); return 0; 生产者与消费者问题: F F:Microsoft Visual StuclioiMyProjects3作累统bb 3TDebug作票统- 5264 4956 523 495 G 52 495 5264 495 495 B 2 4?5t 5跖崎 4956 526 4956 5264 4956 4956 5264 4956 5
9、2fi4 ConSunT produce! Co nsuRit producef cansunt producef cansunt producel consunif ppoducet consunit produce? consul* produce* consult produce? consun* ptoduce? consunt pLoduce* consunt pi?oduce* cansurnt #inelude #include semaphore.h #include thread.h #inelude using namespacestd; Sema phore full(5
10、); Sema phore emp ty(5); Sema phore mutex(1); int cou nt=O; un sig nedi nt WINA PI P roducer( void *p) while(TRUE) emp ty. P(); mutex. P(); cout GetCurre ntThreadld() p roduce!e ndl; mutex.V(); full.V(); Slee p(ra nd()%1000); un sig nedi nt WINA PI Co nsumer(void *p) while(TRUE) full. P(); mutex. P(); cout GetCurre ntThreadld() con sum!e ndl; mutex.V(); emp ty.V(); Slee p(ra nd()%1000); int mai n() HANDLE hThread2; hThread0 = startThread(
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度城市地下综合管廊建设代理合同4篇
- 2025版模具材料定制与销售合同4篇
- 二零二五年度畜牧饲养产业绿色低碳发展合作合同4篇
- 二零二五年度体育设施铁棚搭建及安全保障协议3篇
- 2025年度母子公司数字化转型技术支持合同4篇
- 二零二五年度奶牛养殖场动物福利保障服务合同4篇
- 二零二五年度高端防盗门定制销售服务合同范本3篇
- 2025年度个人房屋买卖合同二零二五年度规范版
- 2025年度建筑工地抽水作业安全责任合同4篇
- 2025年度婴幼儿奶粉质量安全监控及检验合同范本4篇
- 2024企业答谢晚宴会务合同3篇
- 电气工程及其自动化专业《毕业设计(论文)及答辩》教学大纲
- 《客舱安全管理与应急处置》课件-第14讲 应急撤离
- 中华人民共和国文物保护法
- 节前物业安全培训
- 阿里巴巴国际站:2024年珠宝眼镜手表及配饰行业报告
- 高甘油三酯血症相关的器官损伤
- 手术室护士考试题及答案
- 牙膏项目创业计划书
- 单位食堂供餐方案
- DB42-T 2204-2024 湖沼湿地温室气体通量监测技术规范
评论
0/150
提交评论