操作系统概念(第七版_英文版)ch6

操作系统概念(第七版_英文版)ch6

ID:38367554

大小:1.11 MB

页数:69页

时间:2019-06-11

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

《操作系统概念(第七版_英文版)ch6》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、Chapter6:ProcessSynchronizationModule6:ProcessSynchronizationBackgroundTheCritical-SectionProblemPeterson’sSolutionSynchronizationHardwareSemaphoresClassicProblemsofSynchronizationMonitorsSynchronizationExamplesAtomicTransactionsBackgroundConcurrentaccesstoshareddatamayresultindatain

2、consistencyMaintainingdataconsistencyrequiresmechanismstoensuretheorderlyexecutionofcooperatingprocessesSupposethatwewantedtoprovideasolutiontotheconsumer-producerproblemthatfillsallthebuffers.Wecandosobyhavinganintegercountthatkeepstrackofthenumberoffullbuffers.Initially,countissett

3、o0.Itisincrementedbytheproducerafteritproducesanewbufferandisdecrementedbytheconsumerafteritconsumesabuffer.SharedMemoryProducer:/*produceanitemandputinnextProduced*/while(true){while(count==BUFFER_SIZE);//donothingbuffer[in]=nextProduced;in=(in+1)%BUFFER_SIZE;count++;}Consumer:/*con

4、sumetheiteminnextConsumed*/while(true){while(count==0);//donothingnextConsumed=buffer[out];out=(out+1)%BUFFER_SIZE;count--;}RaceConditioncount++couldbeimplementedasregister1=count register1=register1+1 count=register1count--couldbeimplementedasregister2=count register2=register2-1 co

5、unt=register2Considerthisexecutioninterleavingwith“count=5”initially:S0:producerexecuteregister1=count{register1=5} S1:producerexecuteregister1=register1+1{register1=6} S2:consumerexecuteregister2=count{register2=5} S3:consumerexecuteregister2=register2-1{register2=4} S4:producerexec

6、utecount=register1{count=6} S5:consumerexecutecount=register2{count=4}WhataboutthecaseifwereversedtheorderofthestatementsatS4andS5?RaceCondition:theoutcomeoftheexecutiondependsontheparticularorderinwhichtheaccesstakesplace.register1andregister2maybethesamephysicalregister,whatwillhap

7、pen?Critical-SectionProblemCritical-Section:inwhichtheprocessesmaybechangingcommonvariables,updatingatable,writingafile,andsoonWemustdesignaprotocolthattheprocessescanusetocooperate,whenoneprocessisexecutinginitscriticalsection,nootherprocessistobeallowedtoexecuteinthiscriticalsectio

8、n.Entrysecti

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

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

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