已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 增量合同情况说明模板(3篇)
- 安全风险分析工具与合规性检查模板
- 秋天的枫叶美景描写8篇范文
- 2025年文化创意产业发展策略与国际合作研究报告及未来发展趋势预测
- 香港劳工电工考试题库及答案
- 维修电工二级技师考试题库及答案
- 电工绳结技能考试题库及答案
- 妈妈的围巾家的温暖写物(11篇)
- 2025年数字内容行业数字内容与娱乐产业研究报告及未来发展趋势预测
- 2025年汽车智能网联行业智能网联汽车技术发展研究报告及未来发展趋势预测
- 技术开发合同协议书范本
- 知道智慧树农产品市场营销满分测试答案
- 运维工具管理制度
- 患病人员管理办法
- 室内轮式智能巡检机器人 - 采购技术条件书81
- 安徽省合肥市2024–2025学年高二化学上学期期中试卷【含答案】
- 养老院洗浴护理课件
- 养老九防培训课件
- 2025全球智能体发展进展、面临挑战与对策建议报告-赛迪智库
- 2026高考物理大一轮复习-第三章 阶段复习(一) 力与直线运动-专项训练【含答案】
- 船舶修理质量通病防治措施
评论
0/150
提交评论