chapter 06 os concurrency deadlock and starvation
TRANSCRIPT
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
1/52
Chapter 6
Concurrency: Deadlock andStarvation
Operating Systems:Internals and Design Principles, 6/E
William Stallings
Patricia Roy
Manatee Community College, Venice, FL
2008, Prentice Hall
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
2/52
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
3/52
Deadlock
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
4/52
Deadlock
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
5/52
Deadlock
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
6/52
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
7/52
Reusable Resources
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
8/52
Reusable Resources
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
9/52
Reusable Resources
Space is available for allocation of
200Kbytes, and the following sequence of
events occur
Deadlock occurs if both processes
progress to their second request
P1
. . .
. . .Request 80 Kbytes;
Request 60 Kbytes;
P2
. . .
. . .Request 70 Kbytes;
Request 80 Kbytes;
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
10/52
Consumable Resources
Created (produced) and destroyed
(consumed)
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
11/52
Example of Deadlock
Deadlock occurs if receives blocking
P1
. . .
. . .Receive(P2);
Send(P2, M1);
P2
. . .
. . .Receive(P1);
Send(P1, M2);
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
12/52
Resource Allocation Graphs
Directed graph that depicts a state of the
system of resources and processes
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
13/52
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
14/52
Conditions for Deadlock
No preemption
No resource can be forcibly removed form a
process holding it
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
15/52
Resource Allocation Graphs
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
16/52
Resource Allocation Graphs
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
17/52
Possibility of Deadlock
Mutual Exclusion
No preemption
Hold and wait
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
18/52
Existence of Deadlock
Mutual Exclusion
No preemption
Hold and wait Circular wait
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
19/52
Deadlock Prevention
Mutual Exclusion
Must be supported by the OS
Hold and Wait
Require a process request all of its required
resources at one time
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
20/52
Deadlock Prevention
No Preemption
Process must release resource and request
again
OS may preempt a process to require it
releases its resources
Circular Wait
Define a linear ordering of resource types
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
21/52
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
22/52
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
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
23/52
Resource Allocation Denial
Referred to as the bankers algorithm
State of the system is the current
allocation of resources to process
Safe state is where there is at least one
sequence that does not result in deadlock
Unsafe state is a state that is not safe
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
24/52
Determination of a Safe State
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
25/52
Determination of a Safe State
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
26/52
Determination of a Safe State
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
27/52
Determination of a Safe State
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
28/52
Determination of an Unsafe
State
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
29/52
Deadlock Avoidance Logic
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
30/52
Deadlock Avoidance Logic
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
31/52
Deadlock Avoidance
Maximum resource requirement must be
stated in advance
Processes under consideration must be
independent; no synchronization
requirements
There must be a fixed number of
resources to allocate
No process may exit while holding
resources
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
32/52
Deadlock Detection
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
33/52
Strategies Once Deadlock
Detected Abort all deadlocked processes
Back up each deadlocked process to
some previously defined checkpoint, and
restart all process
Original deadlock may occur
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
34/52
Strategies Once Deadlock
Detected Successively abort deadlocked processes
until deadlock no longer exists
Successively preempt resources until
deadlock no longer exists
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
35/52
Advantages and Disadvantages
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
36/52
Dining Philosophers Problem
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
37/52
Dining Philosophers Problem
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
38/52
Dining Philosophers Problem
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
39/52
Dining Philosophers Problem
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
40/52
Dining Philosophers Problem
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
41/52
UNIX Concurrency Mechanisms
Pipes
Messages
Shared memory Semaphores
Signals
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
42/52
UNIX Signals
Li K l C
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
43/52
Linux Kernel Concurrency
Mechanism Includes all the mechanisms found in
UNIX
Atomic operations execute without
interruption and without interference
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
44/52
Linux Atomic Operations
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
45/52
Linux Atomic Operations
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
46/52
Linux Spinlocks
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
47/52
Linux Semaphores
Li M B i
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
48/52
Linux Memory Barrier
Operations
S l i Th d S h i ti
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
49/52
Solaris Thread Synchronization
Primitives Mutual exclusion (mutex) locks
Semaphores
Multiple readers, single writer
(readers/writer) locks
Condition variables
S l i S h i ti D t
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
50/52
Solaris Synchronization Data
Structures
Wi d S h i ti
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
51/52
Windows Synchronization
Objects
-
7/31/2019 Chapter 06 OS Concurrency Deadlock and Starvation
52/52
http://users.erols.com/ziring/diningAppletDemo.html