- 1、本文档共68页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
操作系统课件4_2
吸烟者问题-problem statement 3 supplier processes: X: supplies tobacco and match; Y: supplies match and wrapper; Z: supplies wrapper and tobacco. 3 smoker processes: A: possess tobacco; B: possess match; C: possess wrapper. (1) only one of X,Y,Z can supply at a time; (2) X,Y,Z can proceed only after consumption. * Traditional semaphore: Var t,m,w,s:semaphore; (0,0,0,1) Process X process Y process Z P(s); P(s); P(s); V(t); V(m); V(w); V(m); V(w); V(t); Process A Process B process C P(m); P(w); P(t); P(w); P(t); P(m); smoke; smoke; smoke; V(s); V(s); V(s); * Simultaneous P-operation Heres the code for the agent process. 1 do forever { 2 P( lock ); 3 randNum = rand( 1, 3 ); // Pick a random number from 1-3 4 if ( randNum == 1 ) { 5 // Put tobacco on table 6 // Put paper on table 7 V( smoker_match ); // Wake up smoker with match 8 } else if ( randNum == 2 ) { 9 // Put tobacco on table 10 // Put match on table 11 V( smoker_paper ); // Wake up smoker with paper 12 } else { 13 // Put match on table 14 // Put paper on table 15 V( smoker_tobacco ); } // Wake up smoker with tobacco 16 V( lock ); 17 P( agent ); // Agent sleeps 18 } // end forever loop * Simultaneous P-operation give code to one of the smokers. The others are analogous. 1 do forever { 2 P( smoker_tobacco ); // Sleep right away 3 P( lock ); 4 // Pick up match 5 // Pick up paper 6 V( agent ); 7 V( lock ); 8 // Smoke (but dont inhale). 9 } * Simultaneous P-operation The smoker immediately sle
您可能关注的文档
- 控制血糖的目标值和意义-董吁刚-1010.pptx
- 控诉与申诉--外贸单据.ppt
- 推广需自我营销与颠覆!.ppt
- 探密第一推动.doc
- 描写人物性格的英语形容词.doc
- 推断后续内容.ppt
- 描写人性格的单词.docx
- 接触是预付费燃气表设计.doc
- 推展阅读Riding on an Airplane.pptx
- 描写及叙述文体翻译.ppt
- T∕HNTI 056-2023 茶叶茶氨酸加工技术规程.pdf
- T∕HNSZCYXH 004-2023 潇湘竹品 燃料用竹炭.pdf
- T∕HSPP 0016-2024 含多肽微生物肥料.pdf
- T∕HBSLSC 001-2024 “河北省绿色品牌”认定规范.pdf
- T∕HIS 019-2024 电能计量接线模拟训练试验装置.pdf
- T∕HNTI 059-2023 金花散茶加工技术规程.pdf
- T∕HNTI 058-2023 桃江竹叶茶树栽培技术规程.pdf
- T∕HBIQA 0002.5-2024 食品中非法添加药物利莫那班的快速检测拉曼光谱法.pdf
- T∕HEESA 0001-2024 输变电工程建设过程碳排放计算导则.pdf
- T∕HPAE 0030-2024 绿色设计产品评价技术规范 非固体电解质铝电容器.pdf
文档评论(0)