0% found this document useful (0 votes)
4 views

Lecture 3

Uploaded by

naheba6024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Lecture 3

Uploaded by

naheba6024
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

Concurrency:

Deadlock and Starvation

Chapter 6

7
Agenda
• Principles of Deadlock
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• An Integrated Deadlock Strategy
• Dining Philosophers Problem
• Linux Kernel Concurrency
Mechanisms
8
Deadlock
• Permanent blocking of a set of processes
that either compete for system resources or
communicate with each other
• No efficient solution
• Involve conflicting needs for resources by
two or more processes

9
• A common example is the traffic deadlock.

• Next Figure-a shows a situation in which


four cars have arrived at a four-way stop
intersection at approximately the same time.

• The four quadrants of the intersection are


the resources over which control is needed.

10
11
• In particular, if all four cars wish to go straight
through the intersection, the resource
requirements are as follows:
• Car 1, traveling north, needs quadrants a and
b.
• Car 2 needs quadrants b and c.
• Car 3 needs quadrants c and d.
• Car 4 needs quadrants d and a.

12
• Joint progress diagram , illustrates the
progress of two processes competing for
two resources. Each process needs exclusive
use of both resources for a certain period of
time.
• Two processes, P and Q, have the following
general form:

13
14
• The figure shows six different execution paths.
These can be summarized as follows:

15
• The gray-shaded area of Figure which can be
referred to as a fatal region , applies to the
commentary on paths 3 and 4.

• If an execution path enters this fatal region, then
deadlock is inevitable. Note that the existence of a
fatal region depends on the logic of the two
processes.

• However, deadlock is only inevitable if the joint


progress of the two processes creates a path that
enters the fatal region.

16
• Whether or not deadlock occurs depends on both
the dynamics of the execution and on the details
of the application.

• For example, suppose that P does not need both


resources at the same time so that the two
processes have the following form:

17
This situation is reflected in this Figure.
Some thought should convince you that regardless of the relative timing of
the two processes, deadlock cannot occur.

18
19
Reusable Resources
• Used by only one process at a time and not
depleted by that use
• Processes obtain resources that they later
release for reuse by other processes
• Examples of reusable resources are Processors,
I/O channels, main and secondary memory,
devices, and data structures such as files,
databases, and semaphores
• Deadlock occurs if each process holds one
resource and requests the other
20
As an example of deadlock involving reusable resources,
consider two processes that compete for exclusive access to a
disk file D and a tape drive T.

Deadlock occurs if each process holds one resource and


requests the other. For example, deadlock occurs if the
multiprogramming system interleaves the execution of the
two processes as follows: 21
Another Example of Deadlock

• Space is available for allocation of 200Kbytes,


and the following sequence of events occur

P1 P2
... ...
Request 80 Kbytes; Request 70 Kbytes;
... ...
Request 60 Kbytes; Request 80 Kbytes;

• Deadlock occurs if both processes progress


to their second request
22
23
Consumable Resources
• Created (produced) and destroyed
(consumed)
• Examples of consumable resources are
Interrupts, signals, messages, and
information in I/O buffers
• Deadlock may occur if a Receive message
is blocking
• May take a rare combination of events to
cause deadlock
24
Example of Deadlock

• Deadlock occurs if receive is blocking

P1 P2
... ...
Receive(P2); Receive(P1);
... ...
Send(P2, M1); Send(P1, M2);

25
26
Resource Allocation Graphs
• Directed graph that depicts a state of the
system of resources and processes

27
Within a resource node, a
dot is shown for each
instance of that resource.

Examples of resource types


that may have multiple
instances are I/O devices
that are allocated by a
resource management
module in the OS.

28
-------- 29
Agenda
Principles of Deadlock
• Deadlock Prevention
• Deadlock Avoidance
• Deadlock Detection
• An Integrated Deadlock Strategy
• Dining Philosophers Problem
• Linux Kernel Concurrency
Mechanisms
30
Conditions for Deadlock
• Mutual exclusion
– Only one process may use a resource at a time
• Hold-and-wait
– A process may hold allocated resources while
awaiting assignment of others
• No preemption
– No resource can be forcibly removed form a
process holding it

31
• Circular wait
– A closed chain of processes exists, such that
each process holds at least one resource
needed by the next process in the chain

32
Three general approaches exist for dealing with deadlock.
First, one can prevent deadlock by adopting a policy that eliminates one
of the conditions (conditions 1 through 4).

Second, one can avoid deadlock by making the appropriate


dynamic choices based on the current state of resource allocation.

Third, one can attempt to detect the presence of deadlock (conditions 1


through 4 hold) and take action to recover.
Deadlock Prevention
• We can view deadlock prevention methods
as falling into two classes.
• An indirect method of deadlock prevention
is to prevent the occurrence of one of the
three necessary conditions listed previously
(items 1 through 3).
• A direct method of deadlock prevention is to
prevent the occurrence of a circular wait
(item 4).
34
Deadlock Prevention
• Mutual Exclusion
– Must be supported by the operating system

• Hold and Wait


– Require a process request all of its required
resources at one time

35
Deadlock Prevention
• No Preemption
– Process must release resource and request
again
– Operating system may preempt a process to
require it releases its resources
• Circular Wait
– The circular-wait condition can be prevented by
Defineing a linear ordering of resource types.
(If a process has been allocated resources of type R, then it may
subsequently request only those resources of types following R in
the ordering.) 36
Deadlock Prevention

37
38
Deadlock Avoidance
• In deadlock prevention , we constrain resource
requests to prevent at least one of the four
conditions of deadlock.

• This is either done indirectly, by preventing one of


the three necessary policy conditions (mutual
exclusion, hold and wait, no preemption),
or directly, by preventing circular wait.

• This leads to inefficient use of resources and


inefficient execution of processes. 39
Deadlock Avoidance
• Deadlock avoidance , on the other hand, allows
the three necessary conditions but
makes wise choices to assure that the deadlock
point is never reached.

• As such, avoidance allows more concurrency than


prevention.
• With deadlock avoidance, A decision is made
dynamically whether the current resource
allocation request will, if granted, potentially lead to
a deadlock.
• Requires knowledge of future process requests
Two Approaches to Deadlock Avoidance

• Do not start a process if its demands might


lead to deadlock

• Do not grant an incremental resource


request to a process if this allocation might
lead to deadlock

41

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy