os 操作系统 死锁 deadlock

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

can be represented textually or graphically consist of process set P, resource set R and edge set E edges may be assignment edges or request edges
CPU, memory space, files, I/Odevices
If
a process requests a resource, and it is not available, the process may be put to sleep If the resource being waited on is never released, the process will never restart
Deadlocks
Concepts
A
computer system consists of a finite number of resources to be distributed among competing processes The resources are partitioned into several types, each of which consists of some number of identical instances
KXC254 Operating Systems
Week 6
Deadlocks
School of Computing and Information Systems University of Tasmania
Week 6
Deadlock
definition Deadlock conditions Resource allocation graph Deadlock prevention Deadlock avoidance Deadlock detection and recovery
Understanding Deadlock
Necessary Conditions
Deadlock

can only occur if the following four conditions hold simultaneously
mutual exclusion: at least one resource type must be held in a non-shareable mode, ie, only one process can use it hold & wait: a process is holding a resource, and is waiting on another resource allocated to another process no pre-emption: a resource can be released only voluntarily by the process holding it circular wait - process P1 is waiting on x, x is held by process P2, P2 is waiting on y, y is held by P1
Deadlock Prevention
Allow

resource pre-emption



Necessary Conditions
The

four conditions are not completely independent
The circular wait condition implies the hold-and-wait condition but it’s useful to consider each condition separately (see Deadlock Prevention later)
Concepts
A
set of processes is in a deadlock state when every process in the set is waiting for an event that can be caused by only another process in the set
P1
P2
P3
• •
R2
P 2 R 3 P 3 R 2 P 2
cycle, deadlock
Resource Allocation Graphs
• •
R1 P2
P1
P3
P 1 R 1 P 3 R 2 P 1
cycle, no deadlock
• •
R2 P4
Handling Deadlocks
Concepts
The

normal mode of operation:

Request – if the request can not be granted immediately then the requesting process must wait until it can get the resource Use – the process can operate on the resource Release – the process releases the resource
Request
and release of resources can be accomplished through the wait and signal operations on semaphores
Concepts
Processes

compete for limited resources
Concepts
Concepts
Concepts
Threads
are good candidates for deadlock because multiple threads can compete for shared resources In a deadlock, processes never finish executing and systems resources are tied up, preventing other jobs from starting
ห้องสมุดไป่ตู้
Resource Allocation Graphs
Graphical

representation
P1 R1 P2 R2
processes

resources


• •
(2 instances)
edges

request edge assignment edge
Resource Allocation Graphs

pretend it won’t happen! Used by most operating systems, including Unix and Windows
Handling Deadlocks
Deadlock
prevention: ensuring that at least one of the 4 necessary conditions can not hold Deadlock avoidance: given in advance additional information concerning which resources a process will request and use during its life time, allocate resources carefully
Deadlock Prevention
Preventing

hold and wait


guarantee that when a process requests a resource, it does not hold any other resources One method requires each process to request and be allocated all needed resources before it begins execution may lead to resources being held but idle for lengthy periods
Handling Deadlocks – Deadlock Prevention
Deadlock Prevention
Can

prevent deadlock by preventing one of the four deadlock conditions
mutual exclusion hold & wait no pre-emption circular wait

No
cycle, no deadlock Examples of cycles (next slide)

P1 R1 P2 R3 P3 R2 P1 P2 R3 P3 R2 P2

Resource Allocation Graphs
R1 • • R3
R1 • • R2
P1
P2
P3
• •
R3
• • •
R4
Resource Allocation Graphs
If

resource allocation graph has a cycle
if only one instance of each resource, there is deadlock more than one resource instance, may be deadlock
Concepts
The

request and release of resources are system calls, examples are:


request and release device open and close file allocate and free memory
Handling Deadlocks
Ensure

you never enter a deadlock state
Deadlock prevention Deadlock avoidance
Permit
deadlock, but detect & recover The ostrich algorithm
May
result in low device utilisation and reduced system throughput
Deadlock Prevention
Preventing

mutual exclusion

can only do this for shareable resources (read only files), a process never needs to wait for a shareable resource not suitable for non-shareable resources, eg. files open for write, printers
Resource Allocation Graphs
Textual

representation
set of processes P = {P1, P2, P3, …} set of resources R = {R1, R2, R3, …} set of edges E = {P1R1, P2 R3, R1 P2, R2 P3, …}

Resource Allocation Graphs
Resource Allocation Graphs
Deadlocks
can be described more precisely using a system resource allocation graph, which represents resource allocation
相关文档
最新文档