You are on page 1of 47

OPERATING

SYSTEM: CSET209
OUTLINE

 Deadlock
 Resource Allocation graphs
RESOURCES

 Examples of computer resources


 printers
 tape drives
 tables
 Processes need access to resources in reasonable order
 Suppose a process holds resource A and requests resource B
 at same time another process holds B and requests A
 both are blocked and remain so

3
RESOURCES
 Deadlocks occur when …
 processes are granted exclusive access to devices
 we refer to these devices generally as resources
 Preemptable resources
 can be taken away from a process with no ill effects
 Non-preemptable resources
 will cause the process to fail if taken away

4
RESOURCES

 Sequence of events required to use a resource


1. request the resource
2. use the resource
3. release the resource

 Must wait if request is denied


 requesting process may be blocked
 may fail with error code

5
DEADLOCK EXAMPLE

 A set of blocked processes each holding a resource and waiting to acquire a resource held by another
process in the set
 Example

 semaphores A and B, initialized to 1


P0 P1
wait (A); wait(B)
wait (B); wait(A)
NECESSARY CONDITIONS FOR DEADLOCKS
1. Mutual Exclusion
❖ Definition: Mutual exclusion means that only one process at a time can use a particular
resource. If a process holds a resource, no other process should be allowed to access it until the
holding process releases the resource.

❖ Implication for Deadlock: If all processes have exclusive access to a resource, and a process
is holding a resource while waiting for another, it can lead to a deadlock situation. This is
because the process holding the resource may prevent other processes from proceeding.
2. Hold and Wait
❖ Definition: A process must be holding at least one resource and waiting to acquire additional
resources held by other processes.

❖ Implication for Deadlock: If a process acquires a resource and then waits for another
resource, it holds resources while potentially blocking other processes from acquiring the
resources they need. This holding and waiting pattern can lead to a deadlock when multiple
processes are waiting for resources held by each other.
❖ Prevention: - Design protocols in a way that eliminates the possibility of deadlock.

❖ Avoidance: - Make efforts to prevent deadlock during runtime, ensuring that the system never

enters a deadlocked state.

❖ Detection: - Allow the system to potentially enter a deadlocked state and then detect it.

❖ Ignorance: - Disregarding the problem altogether and pretending that deadlocks do not occur in the

system.
A directed graph used to model resource
requests and allocations.

request edge – directed edge Pi → Rj


assignment edge – directed edge Rj → Pi
RESOURCE-ALLOCATION GRAPH EXAMPLE

• IS THERE A DEADLOCK HERE?

• NO
RESOURCE-ALLOCATION GRAPH EXAMPLE

❖ IS THERE A DEADLOCK HERE?

❖ YES
RESOURCE-ALLOCATION GRAPH EXAMPLE

❖ IS THERE A DEADLOCK HERE?


❖ NO
DEADLOCK IS A PROBABILISTIC EVENT
❑ Suppose there are 3 processes A, B, and C requesting resources R, S, and T as follows.
A B C
Request R Request S Request T
Request S Request T Request R
Release R Release S Release T
Release S Release T Release R

❑ Let the order of execution be


A request R
B request S
C request T
A request S
B request T
C request R

(deadlock)
DEADLOCK IS A PROBABILISTIC EVENT
❑ Suppose there are 3 processes A, B, and C requesting resources R, S, and T as follows.
A B C
Request R Request S Request T
Request S Request T Request R
Release R Release S Release T
Release S Release T Release R

❑ Let the order of execution be


A request R
C request T
A request S
C request R
A release R
A release S

NO deadlock)

You might also like