操作系统概念(第七版英文版).ppt

操作系统概念(第七版英文版).ppt

ID:56373045

大小:773.00 KB

页数:69页

时间:2020-06-14

操作系统概念(第七版英文版).ppt_第1页
操作系统概念(第七版英文版).ppt_第2页
操作系统概念(第七版英文版).ppt_第3页
操作系统概念(第七版英文版).ppt_第4页
操作系统概念(第七版英文版).ppt_第5页
资源描述:

《操作系统概念(第七版英文版).ppt》由会员上传分享,免费在线阅读,更多相关内容在PPT专区-天天文库

1、Chapter6:ProcessSynchronizationModule6:ProcessSynchronizationBackgroundTheCritical-SectionProblemPeterson’sSolutionSynchronizationHardwareSemaphoresClassicProblemsofSynchronizationMonitorsSynchronizationExamplesAtomicTransactionsBackgroundConcurrentaccesstos

2、hareddatamayresultindatainconsistencyMaintainingdataconsistencyrequiresmechanismstoensuretheorderlyexecutionofcooperatingprocessesSupposethatwewantedtoprovideasolutiontotheconsumer-producerproblemthatfillsallthebuffers.Wecandosobyhavinganintegercountthatkeep

3、strackofthenumberoffullbuffers.Initially,countissetto0.Itisincrementedbytheproducerafteritproducesanewbufferandisdecrementedbytheconsumerafteritconsumesabuffer.SharedMemoryProducer:/*produceanitemandputinnextProduced*/while(true){while(count==BUFFER_SIZE);//

4、donothingbuffer[in]=nextProduced;in=(in+1)%BUFFER_SIZE;count++;}Consumer:/*consumetheiteminnextConsumed*/while(true){while(count==0);//donothingnextConsumed=buffer[out];out=(out+1)%BUFFER_SIZE;count--;}RaceConditioncount++couldbeimplementedasregister1=count

5、register1=register1+1 count=register1count--couldbeimplementedasregister2=count register2=register2-1 count=register2Considerthisexecutioninterleavingwith“count=5”initially:S0:producerexecuteregister1=count{register1=5} S1:producerexecuteregister1=register1+

6、1{register1=6} S2:consumerexecuteregister2=count{register2=5} S3:consumerexecuteregister2=register2-1{register2=4} S4:producerexecutecount=register1{count=6} S5:consumerexecutecount=register2{count=4}WhataboutthecaseifwereversedtheorderofthestatementsatS4and

7、S5?RaceCondition:theoutcomeoftheexecutiondependsontheparticularorderinwhichtheaccesstakesplace.register1andregister2maybethesamephysicalregister,whatwillhappen?Critical-SectionProblemCritical-Section:inwhichtheprocessesmaybechangingcommonvariables,updatingat

8、able,writingafile,andsoonWemustdesignaprotocolthattheprocessescanusetocooperate,whenoneprocessisexecutinginitscriticalsection,nootherprocessistobeallowedtoexecuteinthiscriticalsection.Entrysecti

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。