Syllabus | Blank | Homework | ||

Notes | Labs | Scores | Blank |

I know of no more encouraging fact, than the unquestionable ability of man to elevate his life by conscious endeavor.Henry David Thoreau

**Introduction**processes are blocked, waiting on events that could never happen

different from starvation ( the associated resource is in continuous use )

**Four necessary conditions for deadlock**:- mutual exclusion
- hold and wait
- no preemption
- circular wait

*Java Programming*,*OS Principles*,

need the two books to finish project**Deadlock handling strategies**

deadlock prevention, avoidance, detection, recovery**Resource graph for single-unit resource type**cycle => deadlock

deadlock => cycle

**Graph-theoretic model**

**reusable resource**-- can be used again and again ( e.g. CPU, main-memory, I/O devices )

**consumable resource**-- vanish as a result of its use ( e.g. messages, signals )- Created (produced) by a process
- Destroyed (consumed) by a process
- Operations: request/receive (implies consume), produce/send
- Deadlock may occur if the receive operation can block
- Potential deadlock situations are more difficult to detect, and reproduce, by testing

resource access -- can be exclusive or sharedGeneral resource system

- nonempty set of processes P = { P
_{1}, P_{2}, P_{3}, ..., P_{n}}- nonempty set of resources G = { R
_{1}, R_{2}, R_{3}, ..., R_{m}}G = G

_{r}∪ G_{c}

reusable consumableG

_{r}∩ G_{c}= Ø ( disjoint )- for every reusable R
_{i}

t_{i}= |R_{i}| = # of units of resource of type i

≥ 0- for every consumable R
_{i}

there exists subset R C P

producers of R_{i}consumable resource -- concentric rectangle

process -- circle**O**General resource graph

a bi-partite directed graph with set of nodes:

P = { P_{1}, P_{2}, P_{3}, ..., P_{n}}

G = { R_{1}, R_{2}, R_{3}, ..., R_{m}}available units vector ( a

_{1}, a_{2}, a_{3}, ..., a_{m})

A**bi-partite graph**( bigraph ) is a graph whose nodes can be divided into two disjoint sets such that two adjacent nodes cannot come from the same set.for every reusable resource R

_{i}:- # of assignment edges #( R
_{i}, * ) ≤ t_{i} - a
_{i}= t_{i}- #(R_{i}, * ) - a process cannot request more than the total number of
units of a resusable resource

#(P_{j}, R_{i}) ≤ t_{i}- #(R_{i}, P_{j})

for every consumable resource R

_{i}- ( R
_{i}, P_{j}) exists iff P_{j}is a producer of R_{i} - a
_{i}≥ 0

_{i}, R_{j}) > a_{j}=> p_{i}blocked ( more requests than available resources )**Reduction of Resource Graph**

If a process's resource requests can be granted, then we say that the graph can be reduced by that process

( i.e. the process is allowed to complete its execution and return all its resources )

consider reusable resources onlyIf a graph can be reduced by all the processes, then there is **no**deadlock.

If a graph cannot be reduced by all the processes, the irreducible processes constitute the set of deadlock processes in the graphAn example of reduction of an RAG ( Resource Allocation Graph ) Example of RAG with loop but no deadlock Now if we consider

**both**reusable and consumable resources:graph completely reducible => state deadlock free

but deadlock free may**not**=> graph completely reduciblenecessary and sufficient conditions for deadlock

A state is an **expedient**state if all processes having outstanding requests are blocked.Expedient State

if node only has incoming edges =>

**sink**

**Definition**

A**knot**K in a graph is a nonempty set of nodes such that for every node x in K, all nodes in K and only the nodes in K are reachable from x.

( all x, all y ∈ K => x → y ) AND ( all x ∈ K, some z, such that x → z => z ∈ K )

Question: Any knot? Any deadlock?

Question: Any knot? Any deadlock?__Example__**Question**: Any knot in the above figure?**Theorem**- A cycle is a necessary condition for a deadlock.
- If the graph is expedient, then a knot is a sufficient condition for deadlock.
**Note**: A knot is a sufficient condition but**not**a necessary condition for deadlock. (i.e. A set of processes can have deadlock without a knot.)**Systems with Single-unit Requests**- A process can only request one resource unit at a time.
*Theorem*: A knot is a necessary and sufficient condition for deadlock.**Systems with Single-unit Resources**- There is only one unit of every resource.
*Theorem*: A cycle in an*expedient graph*is a necessary and sufficient condition for deadlock.**System with only consumable resources**- such as interrupts, signals, messages, and data in I/O buffers
- deadlock may occur if a
**receive**operation is blocking*Definition*:**claim-limited graph**of a consumable resource system:- each resource has 0 available units
- it has a request edge ( p
_{i}, R_{j}) iff P_{i}is a consumer of R_{j}This claim-limited graph cannot be reduced (R1, R2 has zero available unit) *Theorem*:A consumable resource only system is deadlock free if its claim-limited graph is completely reducible.

But a system may fail the claim-limited graph reducibility test, and still be free from deadlock.__Example__: Both P1 and P2 are producers and consumers.Process P1 Process P2 .

down ( mutex );

critical_section();

up ( mutex );

.

loop.

down ( mutex );

critical_section();

up ( mutex );

.

loop**System with only Reusable Resources**A system is **not**in a deadlock state if and only if the resource graph is completely reducible.**Deadlock Avoidance**requires that the maximum resource requirement of a process be known at every state during its execution ( **claim**of the process )

resource is granted only if the resulting state is safe

a state is**safe**if there exists at least one sequence of execution for all processes such that all of them can run to completion**Trajectory Diagram**__A deadlock path____Question__: What is the difference between a safe state and a deadlock-free state?**How do we know a state is safe?**- Start in the given state
- Simulate running each process to completion, by allocating its maximum resource requirements, and then releasing all resources
- If all processes can complete, the state is safe

**Habermann's Algorithm**( generalization of Dijkstra's Algorithm )n processes, m types of resources

Max-Avail matrix A = ( a where a_{1}a_{2}... a_{m})_{i}= t_{i}= |R_{i}|Max-Claim matrix B = b _{ 11 }b _{ 12 }... b _{ 1m }b _{ 21 }b _{ 22 }... b _{ 2m }. . . . b _{ n1 }b _{ n2 }... b _{ nm }= B _{1}B _{2}. B _{n}_{ij}= max number of units of Resource R_{j}that will ever be held by process P_{i}Allocation matrix C = c _{ 11 }c _{ 12 }... c _{ 1m }c _{ 21 }c _{ 22 }... c _{ 2m }. . . . c _{ n1 }c _{ n2 }... c _{ nm }= C _{1}C _{2}. C _{n}_{ij}= number of units of Resource R_{j}that are currently held by process P_{i}- all k, B
_{k}≤ A ( no process can claim more units of Resources than are available ) - C ≤ B ( no process attempts to request more resources than its maximum claim )

^{n}_{k=1}C _{k}≤ A ( never allocate more resources than are available )- Available matrix D:

D = ( d _{1}d _{2}... d _{m})= A - ^{n}_{k=1}C _{k}_{i}= number of units of Resourc R_{i}available in current state - Need matrix E:

Need matrix E = e _{ 11 }e _{ 12 }... e _{ 1m }e _{ 21 }e _{ 22 }... e _{ 2m }. . . . e _{ n1 }e _{ n2 }... e _{ nm }= B - C = E _{1}E _{2}. E _{n} - Request matrix F:
Request matrix F = f _{ 11 }f _{ 12 }... f _{ 1m }f _{ 21 }f _{ 22 }... f _{ 2m }. . . . f _{ n1 }f _{ n2 }... f _{ nm }= F _{1}F _{2}. F _{n} - tentative state:

Suppose we grant all requests and see what would happen. D ← D - F _{i}( avialable - requests ) C _{i}← C_{i}+ F_{i}( allocated + requests ) E _{i}← E_{i}- F_{i}( need - requests )

The request is granted only if the tentative state is a safe state **Safe-State Check Algorithm**- Pick an unfinished process P
_{i}such that E_{i}≤ D (i.e more resources available than needed by P_{i}). If no such process exists, go to Step 3. - D ← D + C
_{i}. Tag P_{i}as**finished**. Go to step 1. - If all processes are tagged
**finished**, the system state is safe; otherwise it is not safe.

If the system is not safe, the request is blocked and the system state is reset by

D ← D + F _{i}

C_{i}← C_{i}- F_{i}

E_{i}← E_{i}+ F_{i}**finished**in step 2 is reset by:D ← D - C _{i}

and retag P_{i}as**unfinished**.- Pick an unfinished process P
**Example**max-Avail A = ( 2 4 3 ) Max-Claim B = 1 2 2 1 2 1 1 1 1 Allocation C = 1 2 0 0 1 1 1 0 1 Available D = ( 0 1 1 )

Need E = 0 0 2 1 1 0 0 1 0

Suppose process P_{1}makes a requestF _{1}= ( 0 0 1 )The tentative state would be:

Available D = ( 0 1 0 )

Allocation C = 1 2 1 0 1 1 1 0 1 Need E = 0 0 1 1 1 0 0 1 0 _{3}can complete because E_{3}≤ D returning ( 1 0 1 ) to the available pool of resources,D = ( 1 1 1 ) Thus, the outstanding needs of both P

_{1}and P_{2}can be satisfied and consequently the tentative state resulting from the request P_{1}is safe and the request F_{1}of P_{1}can be granted.