Chapter 6 - Concurrency: Deadlock and starvation. This chapter examines two problems that plague all efforts to support concurrent processing: deadlock and starvation. We begin with a discussion of the underlying principles of deadlock and the related problem of starvation. Then we examine the three common approaches to dealing with deadlock: prevention, detection, and avoidance.
Trang 1Chapter 6 Concurrency: Deadlock and
©2008, Prentice Hall
Trang 2that either compete for system resources
or communicate with each other
• No efficient solution
two or more processes
Trang 3Deadlock
Trang 6Reusable Resources
not depleted by that use
release for reuse by other processes
Trang 7Reusable Resources
secondary memory, devices, and data structures such as files, databases, and semaphores
one resource and requests the other
Trang 8Reusable Resources
Trang 9• Space is available for allocation of
200Kbytes, and the following sequence of events occur
progress to their second request
P1
. . . . .
Request 80 Kbytes;
Request 60 Kbytes;
P2
. . . . .
Request 70 Kbytes;
Request 80 Kbytes;
Trang 10Consumable Resources
(consumed)
information in I/O buffers
is blocking
cause deadlock
Trang 11Example of Deadlock
P1
. . . . .
Receive(P2);
Send(P2, M1);
P2
. . . . .
Receive(P1);
Send(P1, M2);
Trang 12Resource Allocation Graphs
system of resources and processes
Trang 13Conditions for Deadlock
Trang 14Conditions for Deadlock
Trang 15Resource Allocation Graphs
Trang 19Deadlock Prevention
– Must be supported by the OS
– Require a process request all of its required resources at one time
Trang 20Deadlock Prevention
– Process must release resource and request again
– OS may preempt a process to require it
releases its resources
– Define a linear ordering of resource types
Trang 21Deadlock Avoidance
the current resource allocation request will, if granted, potentially lead to a
deadlock
requests
Trang 22Two Approaches to Deadlock Avoidance
might lead to deadlock
request to a process if this allocation might lead to deadlock
Trang 23Resource Allocation Denial
allocation of resources to process
sequence that does not result in deadlock
Trang 24Determination of a Safe State
Trang 28Determination of an Unsafe
State
Trang 29Deadlock Avoidance Logic
Trang 32Deadlock Detection
Trang 33Strategies Once Deadlock
Detected
some previously defined checkpoint, and restart all process
– Original deadlock may occur
Trang 34Strategies Once Deadlock
Detected
until deadlock no longer exists
deadlock no longer exists
Trang 35Advantages and Disadvantages
Trang 36Dining Philosophers Problem
Trang 41UNIX Concurrency Mechanisms
Trang 42UNIX Signals
Trang 43Linux Kernel Concurrency
Mechanism
UNIX
interruption and without interference
Trang 44Linux Atomic Operations
Trang 46Linux Spinlocks
Trang 47Linux Semaphores
Trang 48Linux Memory Barrier
Operations
Trang 49Solaris Thread Synchronization
Trang 50Solaris Synchronization Data
Structures
Trang 51Windows Synchronization
Objects