OS02经典进程同步问题2014-2015-2.ppt

  1. 1、本文档共49页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
OS02经典进程同步问题2014-2015-2课件

* * * * 同时wait操作 AND同步操作 * 只要有一个读者,就不允许写了。 * 为实现Reader与Writer进程间在读或写时的互斥而设置了一个互斥信号量Wmutex。另外,再设置一个整型变量Readcount表示正在读的进程数目。由于只要有一个Reader进程在读,便不允许Writer进程去写。因此,仅当Readcount=0,表示尚无Reader进程在读时,Reader进程才需要执行Wait(Wmutex)操作。若Wait(Wmutex)操作成功,Reader进程便可去读,相应地,做Readcount+1操作。同理,仅当Reader进程在执行了Readcount减1操作后其值为0时,才须执行signal(Wmutex)操作,以便让Writer进程写。又因为Readcount是一个可被多个Reader进程访问的临界资源,因此,也应该为它设置一个互斥信号量rmutex。 问题分析: 写者来说:主要写,lock 读者来说:只要有一个,意味不允许再写,加锁。再来,不必,最后通知   互斥锁:读文件时不能写,写文件时不能读文件   读进程:允许多个文件读,读进程时0时,锁定文件,读文件进程1时,解锁;读进程数0时,说明读进程拥有锁   写进程:拥有锁时写文件 * * *     *     * * * * * * 顾客:顾客到达 理发师:理发师准备好 * 理发师:关心的条件:有无顾客来理发 顾客: 理发师状态:sleep 等待 理发 * P(barbers):请求理发师资源,禁止他再为其他用户服务 . he tries to get exclusive access of the barber to cut his hair. * When the barber first comes to the shop, he looks out for any customers i.e. calls P(Customers), if there are none he goes to sleep. Now when a customer arrives, the customer tries to get access to the accessSeats mutex i.e. he calls P(accessSeats), thereby setting a lock. If no free seat (barber chair and waiting chairs) is available he releases the lock i.e. does a V(accessSeats) and leaves the shop. If there is a free seat he first decreases the number of free seats by one and he calls V(Customers) to notify the barber that he wants to cut. Then the customer releases the lock on the accessSeats mutex by calling V(accessSeats). Meanwhile when V(Customers) was called the barber awakes. The barber locks the accessSeats mutex as he wants to increase the number of free seats available, as the just arrived customer may sit on the barber’s chair if that is free. Now the barber releases the lock on the accessSeats mutex so that other customers can access it to the see the status of the free seats. The barber now calls a V(Barber), i.e. he tells the customer that he is available to cut. The customer now calls a P(Barber), i.e. he tries to get exclusive access of the barber to cut his hair. The customer gets a haircut from the barber and as soon a

文档评论(0)

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

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

版权声明书
用户编号:8133070117000003

1亿VIP精品文档

相关文档