1 / 69

Chapter 6 Concurrency: Deadlock and Starvation

Chapter 6 Concurrency: Deadlock and Starvation. Operating Systems: Internals and Design Principles. Operating Systems: Internals and Design Principles.

duyen
Download Presentation

Chapter 6 Concurrency: Deadlock and Starvation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6Concurrency: Deadlock and Starvation Operating Systems:Internals and Design Principles Seventh Edition By William Stallings

  2. Operating Systems:Internals and Design Principles When two trains approach each other at a crossing, both shall come to a full stop and neither shall start up again until the other has gone. Statute passed by the Kansas State Legislature, early in the 20th century. —A TREASURY OF RAILROAD FOLKLORE, B. A. Botkin and Alvin F. Harlow

  3. Deadlock • The permanent blocking of a set of processes that either compete for system resources or communicate with each other • A set of processes is deadlocked when each process in the set is blocked awaiting an event that can only be triggered by another blocked process in the set • Permanent • No efficient solution

  4. Potential Deadlock I need quad C and B I need quad B and C I need quad A and B I need quad D and A

  5. Actual Deadlock HALT until D is free HALT until C is free HALT until B is free HALT until A is free

  6. Joint Progress Diagram

  7. No Deadlock Example

  8. Resource Categories

  9. Reusable Resources Example

  10. Example 2:Memory Request P1 P2 . . . . . . Request 80 Kbytes; Request 70 Kbytes; . . . . . . Request60 Kbytes; Request 80 Kbytes; Space is available for allocation of 200Kbytes, and the following sequence of events occur: Deadlock occurs if both processes progress to their second request

  11. Consumable Resources Deadlock Consider a pair of processes, in which each process attempts to receive a message from the other process and then send a message to the other process: Deadlock occurs if the Receive is blocking

  12. Deadlock Detection, Prevention, and Avoidance

  13. Resource Allocation Graphs

  14. Resource Allocation Graphs

  15. Conditions for Deadlock

  16. Dealing with Deadlock Three general approaches exist for dealing with deadlock:

  17. Deadlock Prevention Strategy • Design a system in such a way that the possibility of deadlock is excluded • Two main methods: • Indirect • prevent the occurrence of one of the three necessary conditions • Direct • prevent the occurrence of a circular wait

  18. Deadlock ConditionPrevention

  19. Deadlock Condition Prevention • No Preemption • if a process holding certain resources is denied a further request, that process must release its original resources and request them again • OS may preempt the second process and require it to release its resources • Circular Wait • define a linear ordering of resource types

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

  21. Two Approaches to Deadlock Avoidance

  22. Resource Allocation Denial Referred to as the banker’s algorithm State of the system reflects the current allocation of resources to processes Safe state is one in which there is at least one sequence of resource allocations to processes that does not result in a deadlock Unsafe state is a state that is not safe

  23. Determination of a Safe State Amount of existing resources Resources available after allocation State of a system consisting of four processes and three resources Allocations have been made to the four processes

  24. P2 Runs to Completion

  25. P1 Runs to Completion

  26. P3 Runs to Completion Thus, the state defined originally is a safe state

  27. Determination of an Unsafe State

  28. Deadlock Avoidance Logic

  29. Deadlock Avoidance Logic

  30. Deadlock Avoidance Advantages It is not necessary to preempt and rollback processes, as in deadlock detection It is less restrictive than deadlock prevention

  31. Deadlock Avoidance Restrictions Maximum resource requirement for each process must be stated in advance Processes under consideration must be independent and with no synchronization requirements There must be a fixed number of resources to allocate No process may exit while holding resources

  32. Deadlock Strategies

  33. Deadline Detection Algorithms • A check for deadlock can be made as frequently as each resource request or, less frequently, depending on how likely it is for a deadlock to occur • Advantages: • it leads to early detection • the algorithm is relatively simple • Disadvantage • frequent checks consume considerable processor time

  34. Deadlock Detection Algorithm

  35. Recovery Strategies Abort all deadlocked processes Back up each deadlocked process to some previously defined checkpoint and restart all processes Successively abort deadlocked processes until deadlock no longer exists Successively preempt resources until deadlock no longer exists

  36. Deadlock Approaches

  37. Dining Philosophers Problem • No two philosophers can use the same fork at the same time (mutual exclusion) • No philosopher must starve to death (avoid deadlock and starvation)

  38. Using Semaphores Solutions Cont.

  39. A Second Solution . . .

  40. Solution Using A Monitor

  41. UNIX Concurrency Mechanisms UNIX provides a variety of mechanisms for interprocessor communication and synchronization including:

  42. Pipes • Circular buffers allowing two processes to communicate on the producer-consumer model • first-in-first-out queue, written by one process and read by another

  43. Messages A block of bytes with an accompanying type UNIX provides msgsnd and msgrcv system calls for processes to engage in message passing Associated with each process is a message queue, which functions like a mailbox

  44. Shared Memory Fastest form of interprocess communication Common block of virtual memory shared by multiple processes Permission is read-only or read-write for a process Mutual exclusion constraints are not part of the shared-memory facility but must be provided by the processes using the shared memory

  45. Semaphores • Generalization of the semWaitand semSignalprimitives • no other process may access the semaphore until all operations have completed

  46. Signals • A software mechanism that informs a process of the occurrence of asynchronous events • similar to a hardware interrupt, but does not employ priorities • A signal is delivered by updating a field in the process table for the process to which the signal is being sent • A process may respond to a signal by: • performing some default action • executing a signal-handler function • ignoring the signal

  47. UNIX Signals

  48. Linux Kernel Concurrency Mechanism • Includes all the mechanisms found in UNIX plus:

  49. Atomic Operations Atomic operations execute without interruption and without interference Simplest of the approaches to kernel synchronization Two types:

  50. Linux Atomic Operations

More Related