






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of deadlocks in computer systems, where processes are blocked due to mutual resource dependencies. Various aspects of deadlocks, including the dining philosophers problem, deadlock conditions, resource-allocation graphs, and methods for handling deadlocks. Prevention, avoidance, and detection techniques are discussed, providing a comprehensive understanding of this important topic.
Typology: Slides
1 / 11
This page cannot be seen from the preview
Don't miss anything!







n locks A and B
n System has 2 tape drives. n P 1 and P 2 each hold one tape drive and each needs another one.
void philosopher (int i) { while (TRUE) { think(); take_fork (i); take_fork ((i+1) % 5); eat(); put_fork (i); put_fork ((i+1) % 5); } }
n Deadlock can arise if four conditions hold simultaneously:
n Mutual exclusion: limited access to limited resources
n Hold and wait
n No preemption: a resource can be released only voluntarily
n Circular wait
P1 is waiting for P2, P2 is waiting for P3, P3 is waiting for P1 or P
Is this a deadlock scenario?
n P1 is waiting for P2 or P3, P3 is waiting for P1 or P
n Is there a deadlock situation here?
n More efficient than obtaining all resources at startup
n State maximum resources needed in advance
n Allocate resources dynamically when needed n Wait if granting request would lead to deadlock n Request can be granted if some sequential ordering of threads is deadlock free
n Sum of maximum resource needs can be greater than the total resources
n There just needs to be some way for all the threads to finish
n For example, allow a thread to proceed if: total available resources – # allocated >= max remaining needs of thread
n If not last fork, grab it n If last fork and requesting thread needs only one more fork, let the thread grab the fork n Else, wait
n If not last fork, grab it n If last fork and requesting thread needs only one more fork, let the thread grab the fork n If last fork, but there is some thread who has two forks, let the requesting thread grab it n Else, wait
n Max : n x m matrix. If Max [ i,j ] = k , then process Pi may request at most k instances of resource type Rj.
n Allocation : n x m matrix. If Allocation[ i,j ] = k then Pi is currently allocated k instances of Rj.
n Need : n x m matrix. If Need [ i,j ] = k , then Pi may need k more instances of Rj to complete its task.
n Available : Vector of length m. If available [ j ] = k , there are k instances of resource type Rj available.
Let n = number of processes, and m = number of resources types.
Requesti = request vector for process Pi. If Requesti [ j ] = k then process Pi wants k instances of resource type Rj.
is restored
n Grant it. Available: [ 2, 2]
n Request granted. Available: [ 1, 1 ]
n Request is not granted. P3 just blocks
n Request is granted. One safe sequence: P2 requests [ 0, 1 ], exhausts needs, finishes execution, releases resources, …
n Request is not granted. P1 just blocks. System waits for P2 to request, finish & release resources
n use wait-for graph if single instance of each resource type n Nodes are processes. n Pi → Pj if Pi is waiting for Pj. n periodically searches for a cycle in the graph; when and how often depends on: n How often a deadlock is likely to occur? n How many processes will need to be rolled back n harder if multiple instances of each resource type
n process termination n resource preemption, roll-back (used in databases)
n prevention n avoidance n detection