操作系统课件4_2.ppt

  1. 1、本文档共68页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 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

文档评论(0)

shuwkb + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档