/
Concurrency Issues Past lectures Problem Safely coordinate access to shared resource Solutions Concurrency Issues Past lectures Problem Safely coordinate access to shared resource Solutions

Concurrency Issues Past lectures Problem Safely coordinate access to shared resource Solutions - PDF document

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
520 views
Uploaded On 2014-12-13

Concurrency Issues Past lectures Problem Safely coordinate access to shared resource Solutions - PPT Presentation

deadlock Starvation threads wait indefinitely eg because some other thread is using a resource Deadlock circular waiting for resources Deadlock starvation but not the other way A Graph Theoretic Model of Deadlock The resource allocation graph RAG B ID: 23580

deadlock Starvation threads wait

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "Concurrency Issues Past lectures Problem..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Deadlock Concurrency Issues Past lectures:Problem: Safely coordinate access to shared resource Solutions: Solutions: Use semaphores, monitors, locks, condition variables What about coordinated access multiple objects?If you are not careful, it can lead to slecture: 2 Todays What is deadlock?How can we address deadlock? Motivating Examples processes share a buffer but use a different protocol for accessing the buffers Producer1() { P( Bff ) Producer2(){ dMLk A postscript interpreter and a visualization program compete for memory frames P( empty e r ) producerMutexLock emptyBuffer P() { l() { 3 P S_Interpreter () { process filerequest(frame_buffer, 1)draw file on screen Visua ize () { request(frame_buffer, 1) The TENEX Case If a process requests all systems buffers, operator console tries to print an error message lock the consolerequest a buffer 4 Deadlock Ready A set of processes is deadlocked when every process in the set is for an event that can onl y be g enerated b y some p rocess in Waiting Tailready queue Tail 5 gygyp the set Starvation vs. deadlockStarvation: threads wait indefinitely (e.g., because some other thread is Deadlock: circular waiting for resourcesstarvation, but not the other way The resource allocation graph ( Basic components of any resource allocation problem Model the state of a computer system as a directed graph G ( V E ) G = = the set of vertices = { i = the set of edges = { ed a resource to a p roces 6 i k request gfmp edges from a process to a resource Resource Allocation GraphsExamples A PostScript interpreter that is waiting for the frame buffer lock and a visualization process that is waiting for memoryvisualizationmemory framesframe buffer lock VisualizationProcess PostScript Interpreter Frame Buffer Interpreter Resource allocation graphs & deadlock Theorem If a resource allocation graph does not contain a cycle then no processes are deadlocked A cycle in a RAG is a necessary condition for deadlock A cycle in a RAG is a necessary condition for deadlock Is the existence of a cycle a sufficient condition? Game VisualizationProcessInterpreter Resource allocation graphs & deadlock Theorem If there is only a single unit of all resources then a set of processes are deadlocked iff there is a cycle in the resource allocationgraph allocation Visualization Memory Frames PostScript 9 Visualization Process PostScript Interpreter Using the TheoryAn operational definition of deadlock Visualization MemoryFrames PSi A set of processes are deadlocked the following conditions hold simultaneously P rocess Frame Buffer P ost t Interpreter 1.Mutual exclusion is required for resource usage (serially useable)2.A process is in a “hold-and-wait” state3.Preemption of resource usage is not allowed4.Circular waiting exists (a cycle exists in the Dealing With DeadlockDeadlock prevention & avoidance tion protocol that ensures deadlock can never occur Ddlkti/id D ea dl oc preven ti on Guarantee that deadlock will never occurGenerally breaks one of the following conditions:Hold-and-waitNo preemptionCircular wait *This is usually the weak link*Deadlock detection and recover y 11 Admit the possibility of deadlock occurring and periodically check for itOn detecting deadlock, abortBreaks the no-preemption conditionWhat does the RAG for a lock look like? Resource Ordering Recall this situation. How can we avoid it? emptyBuffer dMtLk ) producerMutexLock tBff ) p t } B u e r ) :} Eliminate circular waiting by ordering all locks (or semaphores, or resoruces). All code grabs locks in a predefined order. Problems?Maintaining global order is difficult, especially in a large project.Global order can f orce a client to g rab a lock earlier than it 12 would like, tying up a resource for too long.Deadlock is a global property, but lock manipulation is local. Deadlock Detection & RecoveryRecovering from deadlock R1R2R3R4 Abort all deadlocked processes & reclaim their resources Abort one process at a time until all cycles in the Where to start? P4 1 2 3 5P5 Select low priority processProcesses with most allocation of resources Caveat: ensure that system is in consistent state (e.g., transactions) Checkpoint processes periodically; rollback processes to checkpointed state Dealing With DeadlockDeadlock avoidance Examine each resource request and determine whether or not granting the request can lead to deadlock Define a set of vectors and matrices that characterize the resource allocation state matrix R1R2R3... RrP1P2 P 3 n... n1,n Define a set of vectors and matrices that characterize the current state of all resources and processesmaximum claim matrix Max ij = the maximum number of units the number of units of held by process n1, n2, n3, ..., nr� P 3 Pp n 3 , 1 npp,r.......... the maximum number of units of resource that the process ever require simultaneouslythe number of units ofthat are unallocated Dealing With DeadlockDeadlock detection & recovery What are some problems with the banker’s algorithm?Very slow O(n Tooslowtorunoneveryallocation.Whatelsecanwedo? Too What Deadlock prevention and avoidance:Develop and use resource allocation mechanisms and protocols that Deadlock detection and recovery: y stem deadlock and deal with it 15 Detect that a set of processes are deadlockedRecover from the deadlock