




已阅读5页,还剩53页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
.,Concurrency:DeadlockandStarvation,Chapter6,.,Outline,6.1PrincipleofDeadlock6.2Deadlockprevention(死锁预防)6.3Deadlockavoidance(死锁避免)6.4Deadlockdetection(死锁检测),.,6.1Principleofdeadlock,Definition:PermanentblockingofasetofprocessesthateithercompeteforsystemresourcesorcommunicatewitheachotherNoefficientsolutionInvolveconflictingneedsforresourcesbytwoormoreprocesses,.,1、ReusableResources,Usedbyoneprocessatatimeandnotdepleted(消耗掉)bythatuseProcessesobtainresourcesthattheylaterreleaseforreusebyotherprocessesProcessors,I/Ochannels,mainandsecondarymemory,files,databases,andsemaphoresDeadlockoccursifeachprocessholdsoneresourceandrequeststheother,.,ExampleofDeadlock,D,Request60Kbytes;,P2,.,.,Request70Kbytes;,Request80Kbytes;,.,2、ConsumableResources,Created(produced)anddestroyed(consumed)byaprocessInterrupts,signals,messages,andinformationinI/ObuffersDeadlockmayoccurifaReceivemessageisblockingMaytakeararecombinationofeventstocausedeadlock,.,ExampleofDeadlock,Deadlockoccursifreceiveisblocking,P1,.,.,Receive(P2);,Send(P2,M1);,P2,.,.,Receive(P1);,Send(P1,M2);,.,3、ResourceAllocationGraphs,Directedgraphthatdepictsastateofthesystemofresourcesandprocesses,.,ResourceAllocationGraphs,.,.,4、ConditionsforDeadlock,Mutualexclusion(互斥排它性访问资源)onlyoneprocessmayusearesourceatatimeHold-and-wait(占有且等待拥有部分资源,还要请求新的)Aprocessdoesnotrequestallofitsrequiredresourcesatonetime,.,ConditionsforDeadlock,Nopreemption(非剥夺性排他性访问资源)Ifaprocessholdingcertainresourcesisdeniedafurtherrequest,thatprocessmustnotreleaseitsoriginalresourcesIfaprocessrequestsaresourcethatiscurrentlyheldbyanotherprocess,theoperatingsystemisnotallowedtopreemptthesecondprocessandrequireittoreleaseitsresources,.,ConditionsforDeadlock,Circularwait(循环等待在进程资源图中有环路),.,PossibilityofDeadlock,MutualExclusionNopreemptionHoldandwait,.,ExistenceofDeadlock,MutualExclusionNopreemptionHoldandwaitCircularwait,Necessarycondition,.,6.2DeadlockPrevention,Indirectmethod:preventtheoccurrenceofoneofthethreenecessaryconditions(items1through3)Directmethod:preventtheoccurrenceofacircularwait(item4),.,1、Mutualexclusion,Cannotbedisallowed,.,2、HoldandWait,静态分配:Resourcesareallocatedstatically,dynamicrequestsarenotpermitted.Inefficient:BeheldupforalongtimewaitingforallitsresourceResourceallocatedtoaprocessmayremainunusedforalongtime,.,3、NoPreemption,剥夺调度:Whenrequestfurtherresource,releaseitsoriginalresourcesfirst;operatingsystemisallowedtopreempttheresourcesheldbyotherprocess.Onlyappliedtoprocessorormemory,.,4、Circularwait,层次分配:definealinearorderingofresourcetypesandallocatethemaccordingtotheorder,.,6.3DeadlockAvoidance,Allowsthethreenecessaryconditionsbutmakejudiciouschoicestoassurethatthedeadlockpointisneverreached.Adecisionismadedynamicallywhetherthecurrentresourceallocationrequestwill,ifgranted,potentiallyleadtoadeadlockRequiresknowledgeoffutureprocessrequest,.,TwoApproachestoDeadlockAvoidance,DonotstartaprocessifitsdemandsmightleadtodeadlockDonotgrantanincrementalresourcerequesttoaprocessifthisallocationmightleadtodeadlock,银行家算法银行家拥有一笔周转资金客户一开始必须说明其最大需求客户要求分期贷款,如果客户能够得到各期贷款,就一定能够归还贷款,否则就一定不能归还贷款只要客户所要求的最大资金量不超过总周转资金,银行家总会在有限时间内满足其需求。银行家应谨慎的贷款,防止出现坏帐用银行家算法避免死锁操作系统(银行家)操作系统管理的资源(周转资金)进程(要求贷款的客户),Single-resource,Totalresource:10,不死锁,死锁,Safety,Safety,unsafety,Anotherexample,.,1、Processinitiationdenial,.,OnlyRiC(n+1)i+Cki对i=1,.,m,k=1,.,n;Anewprocesswillbestarted.,.,2、ResourceAllocationDenial,ReferredtoasthebankersalgorithmStateofthesystemisthecurrentallocationofresourcestoprocessSafestateiswherethereisatleastonesequencethatdoesnotresultindeadlockUnsafestateisastatethatisnotsafe,Bankeralgorithm,基本思想是:系统中的所有进程进入进程集合,在安全状态下系统收到一个进程的资源请求后,先把资源试探性分配给它。现在,系统用剩下的可用资源和每个进程集合中其他进程还要的资源数作比较,在进程集合中找到剩余资源能满足最大需求量的进程,从而,保证这个进程运行完毕并归还全部资源。这时,把这个进程从集合中去掉,系统的剩余资源更多了,再反复执行上述步骤。最后,检查进程集合,若为空表明本次申请可行,系统处于安全状态,可真正实施本次分配;否则,只要有进程执行不完,系统便处于不安全状态,本次资源分配暂不实施,让申请进程等待,设Request是进程Pi的请求向量。如果Requestj=k,表示进程Pi需要k个Ri类型的资源,进程Pi发出请求后,系统按下述步骤进行检查:(1)如果RequestjClaimij-Allocij,认为出错,因为所需资源数超过了它所宣布的最大值;否则转(2).(2)如果RequestjAvailablej,目前尚无足够资源分配,等待;否则转(3)。(3)系统尝试将所需资源分配给Pi,并修改以下数据结构中的值:Availablej=Availablej-Requestj;Allocij=Allocij+Requestj;(4)进行安全性检查。如果进行了此次资源分配后,系统仍处于安全状态,则分配,否则,尝试分配作废,恢复原来数值,让进程Pi等待。,Safetycheck,定义工作向量currentavail和布尔型标志possible;初始化currentavail:=available,possible:=true;保持possible:=true,从进程集合rest中找出claimk,*-allocationk,*currentavail的进程来,如找到,则释放这个进程Pk的全部资源、执行以下操作currentavail:=currentavail+allocationk,*,把Pk从进程集合中去掉rest:=rest-Pk;否则Possible:=false,停止执行算法;最后查看进程集rest,若为空集返回安全标记;否则返回不安全标记。,.,DeterminationofaSafeStateInitialState,.,DeterminationofaSafeStateP2RunstoCompletion,.,DeterminationofaSafeStateP1RunstoCompletion,.,DeterminationofaSafeStateP3RunstoCompletion,.,DeterminationofanUnsafeState,.,DeterminationofanUnsafeState,.,DeadlockAvoidanceLogic,.,DeadlockAvoidanceLogic,.,DeadlockAvoidance,MaximumresourcerequirementmustbestatedinadvanceProcessesunderconsiderationmustbeindependent;nosynchronizationrequirementsTheremustbeafixednumberofresourcestoallocateNoprocessmayexitwhileholdingresources,.,6.4DeadlockDetection,定义布尔型向量possiblek,k=1,.,n。检测死锁算法如下:(1)标记Allocationk,*全为0的进程,即possiblek:=true;(2)currentavail:=available;(3)在rest中查每一个进程Pk,如果claimk,*-allock,*=0,则possiblek:=true;否则possiblek:=false;这里k=1,.,n。(4)在rest中找一个进程Pk,需满足条件:possiblek=false&(request*currentavail)找到这样的Pk便转(5);否则转(6);(5)currentavail:=currentavail+allocation;possiblek:=true;然后转(4);(6)如果对k=1,.,n若possiblek=true不成立,那么,系统出现了死锁,并且possiblek=false的Pk为死锁进程。,.,StrategiesonceDeadlockDetected,AbortalldeadlockedprocessesBackupeachdeadlockedprocesstosomepreviouslydefinedcheckpoint,andrestartallprocessoriginaldeadlockmayoccurSuccessivelyabortdeadlockedprocessesuntildeadlocknolongerexistsSuccessivelypreemptresourcesuntildeadlocknolongerexists,.,SelectionCriteriaDeadlockedProcesses,LeastamountofprocessortimeconsumedsofarLeastnumberoflinesofoutputproducedsofarMostestimatedtimeremainingLeasttotalresourcesallocatedsofarLowestpriority,.,StrengthsandWeaknessesoftheStrategies,.,6.5Anintegrateddeadlockstrategy,GroupresourcesintoanumberofdifferentresourceclassesUsethelinearorderingstrategydefinedpreviouslyforthepreventionofcircularwaittopreventdeadlocksbetweenrecourseclassesWithinaresourceclass,usethealgorithmthatismostappropriateforthatclass,.,Anexample,resourcesSwappablespace
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 黑龙江大庆市社会保险事业中心招聘笔试历年参考题库附带答案详解
- 安徽2025年安徽望江县融媒体中心招聘急需紧缺专业技术人员笔试历年参考题库附带答案详解
- 上海建桥学院《新能源材料科学基础》2023-2024学年第二学期期末试卷
- 罗定职业技术学院《需求分析与系统设计》2023-2024学年第二学期期末试卷
- 辽宁农业职业技术学院《工程统计》2023-2024学年第二学期期末试卷
- 辽宁师范高等专科学校《大数据基础实践》2023-2024学年第二学期期末试卷
- 衡阳科技职业学院《电视制片人管理》2023-2024学年第二学期期末试卷
- 黑河学院《建筑热工与节能》2023-2024学年第二学期期末试卷
- 山西科技学院《社会体育导论》2023-2024学年第二学期期末试卷
- 长沙南方职业学院《自贸区与国际商务专题》2023-2024学年第二学期期末试卷
- 山东省临沂市2025年普通高等学校招生全国统一考试(模拟)语文及答案(临沂二模)
- 定额〔2025〕1号文-关于发布2018版电力建设工程概预算定额2024年度价格水平调整的通知
- 宫颈癌护理查房-4
- 上海建设工程通用硅酸盐水泥质量检验报告 - 上海水泥行业协会
- NY T 1145-2006 温室地基基础设计丶施工与验收技术规范
- 餐饮服务六大技能培训.ppt
- 基于单片机的电话拨号系统的设计毕业论文
- 叉车产品数据表
- 高填方、深挖路堑边坡和软基监测方案
- 机器人学导论(课堂PPT)
- 机电设备维修与管理专业毕业论文30442
评论
0/150
提交评论