Deadlock: OS Scheduler Determines Which "Ready" Process Runs and When It Should Run
Deadlock: OS Scheduler Determines Which "Ready" Process Runs and When It Should Run
Deadlock: OS Scheduler Determines Which "Ready" Process Runs and When It Should Run
OS Scheduler determines which “ready” process runs and when it should run
- Programmer usually has no control over or visibility into the OS Scheduler
user Wait
Submit Hold Ready
Another example:
Assume a system with four tape drives and two processes.
If each process has 2 tape drives and needs a third one in order to
proceed, then each will wait for the other.
2
Deadlock scenarios are not unique to computing systems
Consider 2 people crossing a river from opposite sides
At most, one foot can be on each stepping stone at a time
To cross the river, a person must use each of the stepping stones
Analogy: Each person crossing the river is a process, the stones are
resources, and the act of stepping onto a stone mutually exclusively
acquires that resource for the process.
Deadlock can occur if:
Person starts to cross river without first checking to see if someone
else is trying to cross from the other side in the opposite direction.
Two people start crossing river from opposite sides and
meet in the middle.
3
Avoiding deadlock requires each person crossing river to follow a protocol.
One such protocol might be to see if anyone is crossing from other side.
If so, wait until they are done. Otherwise, it is safe to cross.
Must also handle situation where 2 people want to cross at "same" time.
If both go, deadlock occurs. (Both stuck in the middle of the river)
If both wait, deadlock also occurs. (Both wait forever)
One solution is to give one side of the river higher priority to break the tie.
But, now given infinite supply from one side, deadlock can still occur.
Modified solution: Periodically alternate the direction of crossing
5
Four Conditions must exist for deadlock to occur
3) No Preemption Condition.
Resources previously granted to a process cannot be forcibly taken away
from that process.
Resources can only be released voluntarily by the processes
that are holding them.
8
Same System of Three Processes (A, B, C) & Three Resources (R, S, T)
- But different ordering (Schedule)
Process A Process B Process C
9
Prevention by negating one of the four necessary conditions for deadlock:
Approach: Examine each of the four necessary conditions for deadlock.
Try to prevent at least one of the conditions from ever happening.
P1 & P2 cannot both have R1 at same time due to mutual exclusion on R1.
14
Also assume: P1 requests R2 at 5 and releases it at 8.
P2 requests R2 at 2 and releases it at 4.
Therefore, shaded region bounded by 5, 8, 2, 4 also cannot be crossed.
P1 & P2 cannot both have R2 at same time due to mutual exclusion on R2.
Some states may appear to be “OK” because processes are still running, but
Deadlock is inevitable once computation enters rectangle U, an unsafe state.
15
16