Sei sulla pagina 1di 4

DEADLOCKS:

System model:
resource types
resource allocation
sequence: request, use, release
concept of deadlocks
Deadlock characterization:
Necessary conditions:
Mutual exclusion
Hold and wait
No preemption
Circular wait
Resource allocation graph:
resource types: rectangle
processes: oval
arrows: request arrow and allocated arrow
resource instances: dots
sets P , R , E: E is set of relations
process states
WHEN DO DEADLOCKS OCCUR:
every process in the system is waiting
4 necessary conditions
Handling deadlocks:
preventing deadlocks : necessary conditioned shouldn't
hold
avoiding deadlocks : info in advance about the resources
a process is going to require
recovering from deadlocks
Prevention:
mutual exclusion: pretty much not possible
because some resources are implicitly non sharable
some shared: read only files
Hold and wait:
each process request and be allocated all it's resources
before it starts exec
this can result in starvation
alternative: a process can request resources only when it
has none
in both, resource utilization can be low and starvation is
possible
No preemption:
preemption used
check if available
if yes allocate
if not, check if it's being held by a process which is waiting
if yes preempt and add to that process waiting list and
allocate to requesting process
if not, the process has to wait
alternately,
as soon as a process starts waiting all the resources held
by it are preempted
Circular wait:
A process can request resources only in an ascending
order of their assigned numbers
EX: if a process p1 wants DVD player and file system
DVD p: 5
file system: 1
it can request DVD p only after requesting for file system
when it is requesting for some resource if it has any higher
order resource it should release it first!
AVOIDANCE:
Safe state
safe sequence
allocate resources to each process in some order and still
avoid deadlock
Resource allocation graph algorithm
claim edge
all the claims should be assigned at the beginning
when a request is made the algorithm checks if the
allocation forms a cycle
if yes the process should wait
if not, it will be assigned and the system is in a safe state
Bankers algorithm:
Data structures:
Available [j]
Max [i,j]
Need [i,j]
Allocation [i,j]
Work and finish are vectors of size m and n where m=
number of resource types n= number of processes
Safety algorithm
step 1: let work and finish be vectors of length m and n
initialize work to available
initialize finish[i] to false for all i from 1 to n
step 2: find an i such that
finish[i]=f
need[i]<=work
if no such i exists goto step4
step 3: work=work+allocate[i]
finish [i] = true
goto step 2
step 4: if finish[i]=true for all i system is in safe state
Request algorithm
if a process pi is requesting for req[…] resources
check if req[i,j] <= need[i,j]
if not error
check if req[i,j] <=available[i,j]
if no error
pretend to have allocated check if safe if yes allocate
if not revert the changes and make the process wait

Potrebbero piacerti anche