版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、1DEADLOCK 6.1. Resource 6.2. Basics 6.3. The ostrich algorithm 6.4. Deadlock detection and recovery 6.5. Deadlock avoidance 6.6. Deadlock prevention 6.7. Other issues Real World Deadlocks?Truck A has to waitfor truck B tomoveNotdeadlockedReal World Deadlocks?Gridlock4ResourcesExamples of computer re
2、sources:- hardware device (e.g. printers) or- piece of information(e.g. locked record in a database)Suppose a process holds resource A and requests resource B and at same time another process holds B and requests A Both are blocked and remain so.5Resources (1)Preemptable resourcescan be taken away f
3、rom a process with no ill effects, e.g. main memoryNonpreemptable resourceswill cause the process to fail if taken away, e.g. CD-Rom6Resources (2)Sequence of events required to use a resourcerequest the resourceuse the resourcerelease the resource Must wait if request is deniedrequesting process may
4、 be blockedmay fail with error codeSystem calls: request or open a special fileCode in figure 6-27Introduction to DeadlocksFormal definition :A set of processes is deadlocked if each process in the set is waiting for an event that only another process in the set can cause.Usually the event is releas
5、e of a currently held resourceNone of the processes can runrelease resourcesbe awakened8Resource Allocation GraphDirected graph with process and resource nodes,arrows indicate request and allocationa) resource R assigned to process Ab) process B is requesting/waiting for resource Sc) process C and D
6、 are in deadlock over resources T and U9A B CHow Deadlock Occurs10A Deadlock-free Run(o) (p) (q)11Four Conditions for DeadlockMutual exclusion conditioneach resource assigned to at most one processHold and wait conditionprocess holding resources can request additional resourceNo preemption condition
7、previously granted resources cannot forcibly taken awayCircular wait conditionmust be a circular chain of two or more processes such thateach is waiting for resource held by next member of the chain12Handling DeadlocksStrategies for dealing with Deadlocksjust ignore the problem altogether prevention
8、 by negating one of the four necessary conditionsdetection and recoverydynamic avoidance by careful resource allocation13The Ostrich AlgorithmPretend there is no problemReasonable if deadlocks occur very rarely cost of prevention is highUNIX and Windows takes this approachIt is a trade off between c
9、onveniencecorrectness14Detection with One Resource of Each Type (1)Deadlock occurs if and only if there is a cycle in the resource allocation graph.Cycles can be checked by a depth-first search.15Detection with Multiple Resources of Each Type (1)Deadlock occurs if each process request is unsatisfiab
10、le.16An example for the deadlock detection algorithm Process 3s request can be granted.What happens if process 3 wants an additional CD-Rom?ExampleFinished = F, F, F, F; Work = Available = (0, 0, 1);R1R2R3P1111P2212P3110P4111R1R2R3P1321P2221P3001P4111AllocationRequestExampleFinished = F, F, T, F; Wo
11、rk = (1, 1, 1);R1R2R3P1111P2212P3110P4111R1R2R3P1321P2221P3P4111AllocationRequestExampleFinished = F, F, T, T; Work = (2, 2, 2);R1R2R3P1111P2212P3110P4111R1R2R3P1321P2221P3P4AllocationRequestExampleFinished = F, T, T, T; Work = (4, 3, 2);R1R2R3P1111P2212P3110P4111R1R2R3P1321P2P3P4AllocationRequestWh
12、en to run Detection Algorithm?For every resource request?For every request that cannot be immediately satisfied?Once every hour?When CPU utilization drops below 40%? 22Recovery from Deadlock (1)Recovery through preemptiontake a resource from some other processdepends on nature of the resourceRecover
13、y through rollbackcheckpoint a process periodicallyuse this saved state restart the process if it is found deadlocked23Recovery from Deadlock (2)Recovery through killing processescrudest but simplest way to break a deadlockkill one of the processes in the deadlock cyclethe other processes get its re
14、sources choose process that can be rerun from the beginning24Deadlock AvoidanceResource TrajectoriesTwo process resource trajectories25Safe StateA state is safe if it is not deadlocked and there is some scheduling order in which every process can run to completion even if they request their maximum
15、number of resources immediately.An unsafe state is a state that is not safe.Note that unsafe does not necessary mean deadlocked.Safe State ExampleSuppose there are 12 tape drives max need current usage could ask forp01055p1422p29273 drives remaincurrent state is safe because a safe sequence exists:
16、p1 can complete with current resourcesp0 can complete with current+p1p2 can complete with current +p1+p0if p2 requests 1 drive, then it must wait to avoid unsafe state.Bankers AlgorithmSuppose we know the “worst case” resource needs of processes in advanceA bit like knowing the credit limit on your
17、credit cards. (This is why they call it the Bankers Algorithm)Observation: Suppose we just give some process ALL the resources it could need Then it will execute to completion. After which it will give back the resources.Like a bank: If Visa just hands you all the money your credit lines permit, at
18、the end of the month, youll pay your entire bill, right?Bankers AlgorithmDecides whether to grant a resource request. Data structures:n: integer # of processesm: integer # of resourcesavailable1.m - availablei is # of avail resources of type imax1.n,1.m- max demand of each Pi for each Riallocation1.
19、n,1.m - current allocation of resource Rj to Pineed1.n,1.mmax # resource Rj that Pi may still requestlet requesti be vector of # of resource Rj Process Pi wantsBasic AlgorithmIf requesti needi then error (asked for too much)If requesti availablei then wait (cant supply it now)Resources are available
20、 to satisfy the requestLets assume that we satisfy the request. Then we would have:available = available - requestiallocationi = allocation i + requestineedi = need i - request iNow, check if this would leave us in a safe state:if yes, grant the request, if no, then leave the state as is and cause p
21、rocess to wait.Safety Checkfree1.m = available /* how many resources are available */finish1.n = false (for all i) /* none finished yet */Step 1: Find an i such that finishi=false and needi = work /* find a proc that can complete its request now */ if no such i exists, go to step 3 /* were done */St
22、ep 2: Found an i:finish i = true /* done with this process */ free = free + allocation i /* assume this process were to finish, and its allocation back to the available list */go to step 1Step 3: If finishi = true for all i, the system is safe. Else NotBankers Algorithm: Example Allocation Max Avail
23、able A B C A B C A B CP0 0 1 0 7 5 3 3 3 2P1 2 0 0 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 this is a safe state: safe sequence Suppose that P1 requests (1,0,2) - add it to P1s allocation and subtract it from AvailableBankers Algorithm: Example Allocation Max Available A B C A B C A B CP0
24、0 1 0 7 5 3 2 3 0P1 3 0 2 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 This is still safe: safe seq In this new state,P4 requests (3,3,0) not enough available resources P0 requests (0,2,0) lets check resulting stateBankers Algorithm: Example Allocation Max Available A B C A B C A B CP0 0 3 0 7
25、 5 3 2 1 0P1 3 0 2 3 2 2 P2 3 0 2 9 0 2 P3 2 1 1 2 2 2 P4 0 0 2 4 3 3 This is unsafe state (why?)So P0s request will be deniedProblems with Bankers Algorithm?34Deadlock PreventionAttacking the Mutual Exclusion ConditionSome devices (such as printer) can be spooledonly the printer daemon uses printer
26、 resourcethus deadlock for printer eliminatedNot all devices can be spooledPrinciple:avoid assigning resource when not absolutely necessaryas few processes as possible actually claim the resource35Attacking the Hold and Wait ConditionRequire processes to request resources before startinga process never has to wait for what it needsProblemsmay not know required resources at start of runalso ties up resources other processes could be usingVariation: process must give up all resourcesthen request all immediately needed36Attacking the No Preemption ConditionThis is not a viable optionCons
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 軍裝式風(fēng)雨衣市場(chǎng)發(fā)展預(yù)測(cè)和趨勢(shì)分析
- 提供臨時(shí)住宅性質(zhì)的應(yīng)急庇護(hù)所服務(wù)行業(yè)營(yíng)銷策略方案
- 醫(yī)療輔助行業(yè)經(jīng)營(yíng)分析報(bào)告
- 情感性精神障礙的護(hù)理
- 可轉(zhuǎn)動(dòng)穿衣鏡市場(chǎng)需求與消費(fèi)特點(diǎn)分析
- 課后輔導(dǎo)班家長(zhǎng)監(jiān)管協(xié)議書
- 短期租車協(xié)議書注意事項(xiàng)
- 垃圾分類游戲制作
- 2024年度工程中介服務(wù)費(fèi)用協(xié)議
- 2024年診所業(yè)務(wù)承接協(xié)議樣例
- 家具制造業(yè)售后服務(wù)預(yù)案
- 電子產(chǎn)品維修合同范本1
- 試用期員工轉(zhuǎn)正規(guī)章制度(8篇)
- 2023-2024學(xué)年全國(guó)小學(xué)二年級(jí)上數(shù)學(xué)人教版期中考試試卷(含答案解析)
- 《籃球原地雙手胸前傳接球》教案 (三篇)
- 3上修改病句練習(xí)
- 2024年廣東茂名高州市教師發(fā)展中心和高州市教育事務(wù)中心選聘歷年高頻難、易錯(cuò)點(diǎn)500題模擬試題附帶答案詳解
- 2024年建筑繼續(xù)教育-一級(jí)建造師繼續(xù)教育考試近5年真題集錦(頻考類試題)帶答案
- 第7章-機(jī)器學(xué)習(xí)
- 2024年秋季新人教版7年級(jí)上冊(cè)生物課件 第2單元 第2章大單元整體設(shè)計(jì)
- 第1課 課題一《課外生活小調(diào)查·周末生活我采訪》(教案)-2024-2025學(xué)年三年級(jí)上冊(cè)綜合實(shí)踐活動(dòng)浙教版
評(píng)論
0/150
提交評(píng)論