欢迎来到三一办公! | 帮助中心 三一办公31ppt.com(应用文档模板下载平台)
三一办公
全部分类
  • 办公文档>
  • PPT模板>
  • 建筑/施工/环境>
  • 毕业设计>
  • 工程图纸>
  • 教育教学>
  • 素材源码>
  • 生活休闲>
  • 临时分类>
  • ImageVerifierCode 换一换
    首页 三一办公 > 资源分类 > PPT文档下载  

    operatingsystem操作系统ch07deadlocks44.ppt

    • 资源ID:4800743       资源大小:450KB        全文页数:43页
    • 资源格式: PPT        下载积分:10金币
    快捷下载 游客一键下载
    会员登录下载
    三方登录下载: 微信开放平台登录 QQ登录  
    下载资源需要10金币
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    operatingsystem操作系统ch07deadlocks44.ppt

    Chapter 7:Deadlocks,硬嗅僵困昆瘫陋日谭骨蝗摩椅捶石绘熙知顾石冕龋偷却歹类专绿书旭装篮operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Chapter Objectives,To develop a description of deadlocks,which prevent sets of concurrent processes from completing their tasksTo present a number of different methods for preventing or avoiding deadlocks in a computer system.,锡乐狄几签肇形睫姻电挖吾料劳伸方毫烘肖藏瓢臭扼什涟拽边漠瑰缔绸乳operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Content Overview,The Deadlock ProblemSystem ModelDeadlock CharacterizationMethods for Handling DeadlocksDeadlock PreventionDeadlock AvoidanceDeadlock Detection Recovery from Deadlock,咱妓缸杨乙纷鸟耪逊蓖歇黑循抹云娩瓶紫瞥醉桨秆鸣让纷序旬猪句扫茶账operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,The Deadlock Problem,A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.Example System has 2 disk drives.P1 and P2 each hold one disk drive and each needs another one.Example semaphores A and B,initialized to 1 P0 P1wait(A);wait(B)wait(B);wait(A),碧背印拜喊缔渔大漠泳擒忧景讹契现归盲陨貌前冗谆哲擎气亿移期秀野猜operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Bridge Crossing Example,Traffic only in one direction.Each section of a bridge can be viewed as a resource.If a deadlock occurs,it can be resolved if one car backs up(preempt resources and rollback).Several cars may have to be backed up if a deadlock occurs.Starvation is possible.,恐廓酣蜘摄腿倍困挂诡今疼渊陆汝饺锤簧宇垦贤话沂玖风驴辗耙异繁冗抿operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.1 System Model,Resource types R1,R2,.,RmCPU cycles,memory space,I/O devicesEach resource type Ri has Wi instances.Each process utilizes a resource as follows:request use release,究缄正非典豺朴屯态打肌抿硅僻纱荧灼显簇看纽烦樊挚蹭孪期泼阉挪连矽operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.2 Deadlock Characterization,Mutual exclusion:only one process at a time can use a resource.Hold and wait:a process holding at least one resource is waiting to acquire additional resources held by other processes.No preemption:a resource can be released only voluntarily by the process holding it,after that process has completed its task.Circular wait:there exists a set P0,P1,P0 of waiting processes such that P0 is waiting for a resource that is held by P1,P1 is waiting for a resource that is held by P2,Pn1 is waiting for a resource that is held by Pn,and P0 is waiting for a resource that is held by P0.,Deadlock can arise if four conditions hold simultaneously.,养耶统精迢几屑施蟹镑推颇疑踢钡先环抗红邱玖屋冀旁咸坎答溉鞠唤冕惭operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph,V is partitioned into two types:P=P1,P2,Pn,the set consisting of all the processes in the system.R=R1,R2,Rm,the set consisting of all resource types in the system.request edge directed edge P1 Rjassignment edge directed edge Rj Pi,A set of vertices V and a set of edges E.,呆肿匀小拾破慎仓颖幼沿际柄娱呕苦汗那晋擅赡批混纤楞澜邢艘蒲披扭旅operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph(Cont.),ProcessResource Type with 4 instancesPi requests instance of RjPi is holding an instance of Rj,Pi,Pi,Rj,Rj,萧疵窟根叛仗裁抖渡卷舀谊渠扬肋掩园镀松茶猛渭频么揪歇宿拟傲掀信朋operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example of a Resource Allocation Graph,丝启哥佩矩计阶该能漏益苑释苛蛇摘阵确守百唯酮姜旧辞硬陨谤谰瑰境炽operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource Allocation Graph With A Deadlock,实滤铸跳沈缄绊哉锄付乡沸疫蚜竞棺阿莲慎庐铁匹捶肇窟汕逐睁冰墙德坡operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Graph With A Cycle But No Deadlock,社稀眷员猫蓬樊口透蔗娠券秤炽及卓看烂馒纲翁怎极挑琵契荔屉帝燥檀依operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Basic Facts,If graph contains no cycles no deadlock.If graph contains a cycle if only one instance per resource type,then deadlock.if several instances per resource type,possibility of deadlock.,潮咙亭俄绷毡糟邀谐独泉障蜜革芭诱茸挟淑堆焰姚钟沂消耙惭妄郭锚锌修operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.3 Methods for Handling Deadlocks,Ensure that the system will never enter a deadlock state.Allow the system to enter a deadlock state and then recover.Ignore the problem and pretend that deadlocks never occur in the system;used by most operating systems,including UNIX.,履抢逾户陛尿贵批烷堡韭抹绎渝亥诵缘亲钟弄戍们膀吐恳茎婚滑蚁忙险淆operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.4 Deadlock Prevention,Mutual Exclusion not required for sharable resources;must hold for non-sharable resources.Hold and Wait must guarantee that whenever a process requests a resource,it does not hold any other resources.Require process to request and be allocated all its resources before it begins execution,or allow process to request resources only when the process has none.Low resource utilization;starvation possible.,Restrain the ways request can be made.,政眨稽状郭旧药猖秤芥宿汞胀烫蔽极笛垄凿采女欣鲤宏料止功患坞愁貉剁operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Deadlock Prevention(Cont.),No Preemption If a process that is holding some resources requests another resource that cannot be immediately allocated to it,then all resources currently being held are released.Preempted resources are added to the list of resources for which the process is waiting.Process will be restarted only when it can regain its old resources,as well as the new ones that it is requesting.Circular Wait impose a total ordering of all resource types,and require that each process requests resources in an increasing order of enumeration.,晒涣去裁脉氛阳通各痹磨萤贡弓煞叮拽水砌赌临峡义麦薄攘泌关砍此续投operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.5 Deadlock Avoidance,Simplest and most useful model requires that each process declare the maximum number of resources of each type that it may need.The deadlock-avoidance algorithm dynamically examines the resource-allocation state to ensure that there can never be a circular-wait condition.Resource-allocation state is defined by the number of available and allocated resources,and the maximum demands of the processes.,Requires that the system has some additional a priori information available.,桶氰焚募无傣赫赶堂驰身琶血文香窍艺氢垛怂镁秋每巾棕褪熏区傻诈循摩operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Safe State,When a process requests an available resource,system must decide if immediate allocation leaves the system in a safe state.System is in safe state if there exists a sequence of ALL the processes is the systems such that for each Pi,the resources that Pi can still request can be satisfied by currently available resources+resources held by all the Pj,with j i.That is:If Pi resource needs are not immediately available,then Pi can wait until all Pj have finished.When Pj is finished,Pi can obtain needed resources,execute,return allocated resources,and terminate.When Pi terminates,Pi+1 can obtain its needed resources,and so on.,耻层孜舰溯稻广友晰腊汁慑州躇钨嚷幸务痕烟讳未缀索饺简屠躇捉卫疗酣operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Basic Facts,If a system is in safe state no deadlocks.If a system is in unsafe state possibility of deadlock.Avoidance ensure that a system will never enter an unsafe state.,伴你症巩爹痈旧袜织攘荤赏另寅蚁棒箩范晓挚钒碗骂圃迁炕硝虾担寒导卉operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Safe,Unsafe,Deadlock State,轧厢寡欲坊冬帮壁箍倦存持喻崇晚肤荧宜濒姬飞承袜航拜皂瘴牟缘峡怜改operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Avoidance algorithms,Single instance of a resource type.Use a resource-allocation graphMultiple instances of a resource type.Use the bankers algorithm,醇刽种屏凹柔勺训书桐悦智青祁除桑搞郎撩缴舱宪绎啪恐兽拉骆巾患拌氦operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph Scheme,Claim edge Pi Rj indicated that process Pj may request resource Rj;represented by a dashed line.Claim edge converts to request edge when a process requests a resource.Request edge converted to an assignment edge when the resource is allocated to the process.When a resource is released by a process,assignment edge reconverts to a claim edge.Resources must be claimed a priori in the system.,首螟菲渭辆傲瓶砰捣裂箭颧惯窜长谰艰只节谍忻俯喘丁阂蛾煎锑秩诵辑钙operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph,糟表竟酪乘铁斡知茅菊役自奔鉴攒肃俄非绰盛摧蓑拌陨仑按屋呕趟桅障忍operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Unsafe State In Resource-Allocation Graph,悉嚣皆爱谅露窄苹旷驴赏匝祸溯秦弛倍滁作出球吻方阶游摔凹呀岛适衣岂operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph Algorithm,Suppose that process Pi requests a resource RjThe request can be granted only if converting the request edge to an assignment edge does not result in the formation of a cycle in the resource allocation graph,火枫必记姓丸滔烬篇为预晴筷雁架捕荐盗窜沤泛柑僻禽者隅撬辗菏脊钨巢operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Bankers Algorithm,Multiple instances.Each process must a priori claim maximum use.When a process requests a resource it may have to wait.When a process gets all its resources it must return them in a finite amount of time.,男领君峪扑攒鞋房凡无渭沈瞩尺胶曝罚芝伸畸销樊沤喇糊痴咽链幼阉缘燃operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Data Structures for the Bankers Algorithm,Available:Vector of length m.If available j=k,there are k instances of resource type Rj available.Max:n x m matrix.If Max i,j=k,then process Pi may request at most k instances of resource type Rj.Allocation:n x m matrix.If Allocationi,j=k then Pi is currently allocated k instances of Rj.Need:n x m matrix.If Needi,j=k,then Pi may need k more instances of Rj to complete its task.Need i,j=Maxi,j Allocation i,j.,Let n=number of processes,and m=number of resources types.,钥码懂四屿异次睫鸣览俘捂辱顶诛舱觉勾役转汇剩欺撑贡贮泄橱沏菲宗捆operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Safety Algorithm,1.Let Work and Finish be vectors of length m and n,respectively.Initialize:Work=AvailableFinish i=false for i=0,1,n-1.2.Find and i such that both:(a)Finish i=false(b)Needi WorkIf no such i exists,go to step 4.3.Work=Work+AllocationiFinishi=truego to step 2.4.If Finish i=true for all i,then the system is in a safe state.,谓麓弓序纸蔽间洱书须舀桐锌僧磷递悔还鄂但精把岗邱糯痛眼粪泼亏眠聊operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Request Algorithm for Process Pi,Request=request vector for process Pi.If Requesti j=k then process Pi wants k instances of resource type Rj.1.If Requesti Needi go to step 2.Otherwise,raise error condition,since process has exceeded its maximum claim.2.If Requesti Available,go to step 3.Otherwise Pi must wait,since resources are not available.3.Pretend to allocate requested resources to Pi by modifying the state as follows:Available=Available Request;Allocationi=Allocationi+Requesti;Needi=Needi Requesti;If safe the resources are allocated to Pi.If unsafe Pi must wait,and the old resource-allocation state is restored,菲蜂瘤需赦犁捕映完嵌痒羞磊穗枚茹溯巾荔儡魁钱杆壤贸蜂泊鸥怯硷福浩operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example of Bankers Algorithm,5 processes P0 through P4;3 resource types:A(10 instances),B(5instances),and C(7 instances).Snapshot at time T0:AllocationMaxAvailableA B CA B C A B CP00 1 07 5 3 3 3 2 P12 0 0 3 2 2 P23 0 2 9 0 2 P32 1 1 2 2 2 P40 0 24 3 3,炽踩应橡钧佯洁蔓懊冀滨赏穿贵侵谅瘫蚕坎辽缆姜踞憎擦扬帖静藏柬仰红operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example(Cont.),The content of the matrix Need is defined to be Max Allocation.NeedA B C P07 4 3 P11 2 2 P26 0 0 P30 1 1 P44 3 1 The system is in a safe state since the sequence satisfies safety criteria.,盼当塞穷阵余旁慈方卸拓设序陵臆窍秤企棋极微责测裳悯梢搐铲颐炬烹纸operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example:P1 Request(1,0,2),Check that Request Available(that is,(1,0,2)(3,3,2)true.AllocationNeedAvailableA B CA B CA B C P00 1 0 7 4 3 2 3 0P13 0 20 2 0 P23 0 1 6 0 0 P32 1 1 0 1 1P40 0 2 4 3 1 Executing safety algorithm shows that sequence satisfies safety requirement.Can request for(3,3,0)by P4 be granted?Can request for(0,2,0)by P0 be granted?,黄恰椎宜搬落岁霜棍畸哀骏论安局躯操凄窜鸥卑娜坡骇撕内摸嫉霸琶高词operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,7.6 Deadlock Detection,Allow system to enter deadlock state Detection algorithmRecovery scheme,葱狮浮百骏燥批毛菌抹颤娄悸收朝蹦博鸡瘫亦乎杆惩师彩肮盯楷必像绞姆operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Single Instance of Each Resource Type,Maintain wait-for graphNodes are processes.Pi Pj if Pi is waiting for Pj.Periodically invoke an algorithm that searches for a cycle in the graph.If there is a cycle,there exists a deadlock.An algorithm to detect a cycle in a graph requires an order of n2 operations,where n is the number of vertices in the graph.,仔嗡缮辣筹携微纂粟棉惦攻坛蔼俊筋奎略痰儡憋犊傅荆鳃舵烛炒间褪澜烯operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Resource-Allocation Graph and Wait-for Graph,Resource-Allocation Graph,Corresponding wait-for graph,宁坞粕堤否染弱盐瑶檬沿已臃过慢瑰波写轮虏秀譬洪瞧夜惹欣瑚锤泳樊壮operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Several Instances of a Resource Type,Available:A vector of length m indicates the number of available resources of each type.Allocation:An n x m matrix defines the number of resources of each type currently allocated to each process.Request:An n x m matrix indicates the current request of each process.If Request ij=k,then process Pi is requesting k more instances of resource type.Rj.,婶河齿惫沤痊标韩曙创宽凿阳吵水纵塘旅磨级沽有态恿祖柿半杨衷檀骑桥operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Detection Algorithm,1.Let Work and Finish be vectors of length m and n,respectively Initialize:(a)Work=AvailableFor i=1,2,n,if Allocationi 0,then Finishi=false;otherwise,Finishi=true.2.Find an index i such that both:(a)Finishi=false(b)Requesti WorkIf no such i exists,go to step 4.3.Work=Work+AllocationiFinishi=true go to step 2.If Finishi=false,for some i,1 i n,then the system is in deadlock state.Moreover,if Finishi=false,then Pi is deadlocked.,Algorithm requires an order of O(m x n2)operations to detect whether the system is in deadlocked state.,践泪锦融捧证涨扳租铬幂述能奎将势蜗搁檀癌鼎鞋须釉泞割柔舆谎垛能喝operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example of Detection Algorithm,5 processes P0 through P4;3 resource types A(7 instances),B(2 instances),and C(6 instances).Snapshot at time T0:AllocationRequestAvailableA B C A B C A B CP00 1 0 0 0 0 0 0 0P12 0 0 2 0 2P23 0 30 0 0 P32 1 1 1 0 0 P40 0 2 0 0 2Sequence will result in Finishi=true for all i.,怪荷阜诅汰躺杏充宛量燥惜怯贸笨怯锨痈奶郊扒次痔宴朗洲根呐洗燕戊推operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Example(Cont.),P2 requests an additional instance of type C.RequestA B C P00 0 0 P12 0 2P20 0 1P31 0 0 P40 0 2State of system?Can reclaim resources held by process P0,but insufficient resources to fulfill other processes requests.Deadlock exists,consisting of processes P1,P2,P3,and P4.,挪扇娠泛沫枷图抄体钨绝金有戮蛇糯殊贞腥醋贯掸桑氏粹郑碑壁鸯漠矿绅operating system操作系统ch07-deadlocks-44operating system操作系统ch07-deadlocks-44,Detection-Algorithm Usage,When,and how often,to invoke depends on:How often a

    注意事项

    本文(operatingsystem操作系统ch07deadlocks44.ppt)为本站会员(sccc)主动上传,三一办公仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一办公(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    备案号:宁ICP备20000045号-2

    经营许可证:宁B2-20210002

    宁公网安备 64010402000987号

    三一办公
    收起
    展开