topik 4 deadlock
TRANSCRIPT
-
8/13/2019 Topik 4 Deadlock
1/22
Pn. Nin Hayati Binti Mohd Yusoff
-
8/13/2019 Topik 4 Deadlock
2/22
EXAMPLES:
"It takes money to make money".
You can't get a job without experience; you can't get experience without a
job.
BACKGROUND:
The cause of deadlocks: Each process needing what another process has. This
results from sharing resources such as memory, devices, links.
Under normal operation, a resource allocations proceed like this:
1. Request a resource (suspend until available if necessary ).
2. Use the resource.
3. Release the resource.
-
8/13/2019 Topik 4 Deadlock
3/22
In a multiprogramming system, processes request resources.
If those resources are being used by other processes then the processenters a waiting state.
However, if other processes are also in a waiting state, we have
deadlock. The formal definition of deadlock is as follows:
A set of processes is in a deadlock state if everyprocess in the set is waiting for an event (release)that can only be caused by some other process in
the same set.
-
8/13/2019 Topik 4 Deadlock
4/22
Process-1 requests the printer, gets it
Process-2 requests the tape unit, gets it Process-1 and
Process-1 requests the tape unit, waits Process-2 are
Process-2 requests the printer, waits deadlocked!
-
8/13/2019 Topik 4 Deadlock
5/22
A process must request a resource before using it. It must release the resource after
using it.
(request -> use -> release)
A process cannot request a number more than the total number of resourcesavailable in the system
-
8/13/2019 Topik 4 Deadlock
6/22
A process cannot request a number more than the total number of resources availablein the systemA set of blocked processes each holding a resource and waiting toacquire a resource held by another process in the set.
Example System has 2 tape drives. P1and P2each hold one tape drive and each needs another one.
Example semaphoresAandB, initialized to 1
P0 P1
wait (A); wait(B)wait (B); wait(A)
-
8/13/2019 Topik 4 Deadlock
7/22
-
8/13/2019 Topik 4 Deadlock
8/22
V is partitioned into two types:
P= {P1, P2, , Pn}, the set consisting of all the processes in the system.
R= {R1, R2, , Rm}, the set consisting of all resource types in the system.
request edge directed edge P1 Rj
assignment edge directed edge Rj Pi
A set of vertices Vand a set of edges E.
-
8/13/2019 Topik 4 Deadlock
9/22
Process
Resource Type with 4 instances
Pirequests instance of Rj
Piis holding an instance of Rj
Pi
Rj
Pi
Rj
-
8/13/2019 Topik 4 Deadlock
10/22
P2 Requests P3
R Assigned to P
-
8/13/2019 Topik 4 Deadlock
11/22
-
8/13/2019 Topik 4 Deadlock
12/22
Methods for handling deadlocks are
Deadlock
prevention
Deadlock
avoidance
Deadlock detection
and recovery
-
8/13/2019 Topik 4 Deadlock
13/22
A deadlock occurs if and only if the following four conditions hold in asystem simultaneously: !
Mutual Exclusion
Hold and Wait
No Preemption
Circular Wait
-
8/13/2019 Topik 4 Deadlock
14/22
There must be at least one process that is holding at least
one resource and waiting for other resources that are being
hold by other processes.
At least one of the resources is non-sharable (that is; only alimited number of processes can use it at a time and if it is
requested by a process while it is being used by another one,
the requesting process has to wait until the resource is
released.).
A deadlock occurs if and only if the following four conditions hold in asystem simultaneously: !
Mutual Exclusion
Hold and Wait
-
8/13/2019 Topik 4 Deadlock
15/22
There exists a set of processes: {P1, P2, ..., Pn} such that
P1 is waiting for a resource held by P2
P2 is waiting for a resource held by P3
...
Pn-1 is waiting for a resource held by Pn
Pn is waiting for a resource held by P1
No resource can be preempted before the holding processcompletes its task with that resource
A deadlock occurs if and only if the following four conditions hold in asystem simultaneously: !
No Preemption
Circular Wait
-
8/13/2019 Topik 4 Deadlock
16/22
If we have prior knowledge of how resources will be requested, it'spossible to determine if we are entering an "unsafe" state.
Possible states are:deadlock - no forward progress can be made.Unsafe state - A state that may allow deadlock.Safe state - A state is safe if a sequence of processes exist such
that there are enough resources for the first to finish, andas each finishes and releases its resources there areenough for the next to finish.
The rule is simple: if a request allocation would cause an unsafe state, donot honor that request.
NOTE: all deadlocks are unsafe, but all unsafes are NOT deadlocks.
-
8/13/2019 Topik 4 Deadlock
17/22
NOTE: all deadlocks are unsafe, but all unsafes are NOT deadlocks
UNSAFE SAFE
DEADLOCK
Only with luck willprocesses avoid
deadlock.
O.S. can avoiddeadlock.
-
8/13/2019 Topik 4 Deadlock
18/22
If a system has no deadlock prevention and no deadlock avoidance
scheme, then it needs a deadlock detection scheme withrecovery from deadlock capability. For this, information should be kept on the allocation of resources to
processes, and on outstanding allocation requests.
Then, an algorithm is needed which will determine whether the system has
entered a deadlock state.
-
8/13/2019 Topik 4 Deadlock
19/22
If the system is in a deadlock state, some methods for recovering it
from the deadlock state must be applied. There are various ways for
recovery:
Allocate one resource to several processes, by violating mutual
exclusion.
Preempt some resources from some of the deadlocked
processes.
Abort one or more processes in order to break the deadlock.
-
8/13/2019 Topik 4 Deadlock
20/22
-
8/13/2019 Topik 4 Deadlock
21/22
ANY QUESTIONS?
-
8/13/2019 Topik 4 Deadlock
22/22
END OF CHAPTER
4.0 RESOURCE MANAGEMENT4.1 Understand Processor Management4.1.1
Explain the role of control blocks and interrupts in the dispatching
process.
4.1.2 Describe the various types of scheduling processes:a. Long-term schedulingb. Medium-term schedulingc. Short-term scheduling