operting system book (5)
Post on 30-May-2018
220 Views
Preview:
TRANSCRIPT
-
8/14/2019 Operting System Book (5)
1/32
Concurrency: Deadlock and
StarvationChapter 6
-
8/14/2019 Operting System Book (5)
2/32
Deadlock
Permanent blocking of a set of processesthat either compete for system resourcesor communicate with each other
No efficient solution Involve conflicting needs for resources
by two or more processes
-
8/14/2019 Operting System Book (5)
3/32
-
8/14/2019 Operting System Book (5)
4/32
-
8/14/2019 Operting System Book (5)
5/32
-
8/14/2019 Operting System Book (5)
6/32
Reusable Resources
Used by one process at a time and notdepleted by that use
Processes obtain resources that they later release for reuse by other processes
Processors, I/O channels, main andsecondary memory, files, databases, and
semaphores Deadlock occurs if each process holdsone resource and requests the other
-
8/14/2019 Operting System Book (5)
7/32
Example of Deadlock
-
8/14/2019 Operting System Book (5)
8/32
Another Example of Deadlock
Space is available for allocation of 200K bytes, and the following sequence of events occur
Deadlock occurs if both processes progress to their second request
P1
. . .
. . .Request 80K bytes;
Request 60K bytes;
P2
. . .
. . .Request 70K bytes;
Request 80K bytes;
-
8/14/2019 Operting System Book (5)
9/32
Consumable Resources
Created (produced) and destroyed(consumed) by a process
Interrupts, signals, messages, andinformation in I/O buffers
Deadlock may occur if a Receivemessage is blocking
May take a rare combination of events tocause deadlock
-
8/14/2019 Operting System Book (5)
10/32
Example of Deadlock
Deadlock occurs if receive is blocking
P1
. . .
. . .Receive(P2);
Send(P2, M1);
P2
. . .
. . .Receive(P1);
Send(P1, M2);
-
8/14/2019 Operting System Book (5)
11/32
Conditions for Deadlock
Mutual exclusion only one process may use a resource at a
time
Hold-and-wait A process request all of its required
resources at one time
-
8/14/2019 Operting System Book (5)
12/32
Conditions for Deadlock
No preemption If a process holding certain resources is
denied a further request, that process must
release its original resources If a process requests a resource that is
currently held by another process, theoperating system may preempt the second
process and require it to release itsresources
-
8/14/2019 Operting System Book (5)
13/32
Conditions for Deadlock
Circular wait Prevented by defining a linear ordering of
resource types
-
8/14/2019 Operting System Book (5)
14/32
Deadlock Avoidance
A decision is made dynamically whether the current resource allocation requestwill, if granted, potentially lead to adeadlock
Requires knowledge of future processrequest
-
8/14/2019 Operting System Book (5)
15/32
Two Approaches toDeadlock Avoidance
Do not start a process if its demandsmight lead to deadlock
Do not grant an incremental resourcerequest to a process if this allocationmight lead to deadlock
-
8/14/2019 Operting System Book (5)
16/32
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
-
8/14/2019 Operting System Book (5)
17/32
Determination of a Safe StateInitial State
-
8/14/2019 Operting System Book (5)
18/32
Determination of a Safe StateP2 Runs to Completion
-
8/14/2019 Operting System Book (5)
19/32
Determination of a Safe StateP1 Runs to Completion
-
8/14/2019 Operting System Book (5)
20/32
Determination of a Safe StateP3 Runs to Completion
-
8/14/2019 Operting System Book (5)
21/32
Determination of anUnsafe State
-
8/14/2019 Operting System Book (5)
22/32
Determination of anUnsafe State
-
8/14/2019 Operting System Book (5)
23/32
Deadlock Avoidance
Maximum resource requirement must bestated in advance
Processes under consideration must be
independent; no synchronizationrequirements
There must be a fixed number of resources to allocate
No process may exit while holdingresources
-
8/14/2019 Operting System Book (5)
24/32
Deadlock Detection
-
8/14/2019 Operting System Book (5)
25/32
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
Successively abort deadlocked processes
until deadlock no longer exists Successively preempt resources untildeadlock no longer exists
-
8/14/2019 Operting System Book (5)
26/32
Selection Criteria DeadlockedProcesses
Least amount of processor timeconsumed so far
Least number of lines of output produced so far
Most estimated time remaining Least total resources allocated so far Lowest priority
-
8/14/2019 Operting System Book (5)
27/32
Dining Philosophers Problem
-
8/14/2019 Operting System Book (5)
28/32
UNIX ConcurrencyMechanisms
Pipes Messages Shared memory Semaphores Signals
-
8/14/2019 Operting System Book (5)
29/32
Solaris ThreadSynchronization Primitives
Mutual exclusion (mutex) locks Semaphores Multiple readers, single writer
(readers/writer) locks Condition variables
-
8/14/2019 Operting System Book (5)
30/32
-
8/14/2019 Operting System Book (5)
31/32
-
8/14/2019 Operting System Book (5)
32/32
Windows 2000 ConcurrencyMechanisms
Process Thread File
Console input File change notification Mutex Semaphore Event Waitable timer
top related