Sie sind auf Seite 1von 22

Pn.

Nin Hayati Binti Mohd Yusoff

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.

In a multiprogramming system, processes request resources. If those resources are being used by other processes then the process enters 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 every process in the set is waiting for an event (release) that can only be caused by some other process in the same set.

Process-1 requests the printer, gets it


Process-2 requests the tape unit, gets it Process-1 requests the tape unit, waits Process-1 and Process-2 are

Process-2 requests the printer,

waits deadlocked!

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 resources available in the system

A process cannot request a number more than the total number of resources available in the systemA set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.

Example System has 2 tape drives. P1 and P2 each hold one tape drive and each needs another one.
Example semaphores A and B, initialized to 1

P0 wait (A); wait (B);

P1 wait(B) wait(A)

Traffic only in one direction.

Each section of a bridge can be viewed as a resource.


If a deadlock occurs, it can be resolved if one car backs up (preempt resources and rollback). Several cars may have to be backed up if a deadlock occurs. Starvation is possible.

A set of vertices V and a set of edges E.


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

Process

Resource Type with 4 instances

Pi requests instance of Rj Pi
Rj

Pi is holding an instance of Rj Pi
Rj

R3 Assigned to P3

P2 Requests P3

Methods for handling deadlocks are

Deadlock prevention Deadlock avoidance Deadlock detection and recovery

A deadlock occurs if and only if the following four conditions hold in a system simultaneously: !

Mutual Exclusion

Hold and Wait

No Preemption

Circular Wait

Mutual Exclusion
At least one of the resources is non-sharable (that is; only a limited 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.).

Hold and Wait


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.

A deadlock occurs if and only if the following four conditions hold in a system simultaneously: !

No Preemption
No resource can be preempted before the holding process completes its task with that resource

Circular Wait
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

A deadlock occurs if and only if the following four conditions hold in a system simultaneously: !

If we have prior knowledge of how resources will be requested, it's possible 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, and as each finishes and releases its resources there are enough for the next to finish. The rule is simple: if a request allocation would cause an unsafe state, do not honor that request. NOTE: all deadlocks are unsafe, but all unsafes are NOT deadlocks.

NOTE: all deadlocks are unsafe, but all unsafes are NOT deadlocks

UNSAFE
DEADLOCK

SAFE

Only with luck will processes avoid deadlock.

O.S. can avoid deadlock.

If a system has no deadlock prevention and no deadlock avoidance scheme, then it needs a

deadlock detection

scheme

with

recovery 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.

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.

ANY QUESTIONS?

END OF CHAPTER
4.0 RESOURCE MANAGEMENT 4.1 Understand Processor Management Explain the role of control blocks and interrupts in the dispatching 4.1.1 process. 4.1.2 Describe the various types of scheduling processes: a. Long-term scheduling b. Medium-term scheduling c. Short-term scheduling

Das könnte Ihnen auch gefallen