More Info on DeadlockSimilar Undetermined MusicSearch Artistopia
Biography
about|the computer science conceptA deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does.
In an operating system , a deadlock is a situation which occurs when a process enters a waiting Process states|state because a resource requested by it is being held by another waiting process, which in turn is waiting for another resource. If a process is unable to change its state indefinitely because the resources requested by it are being used by other waiting process, then the system is said to be in a deadlock.cite book | last=Silberschatz| first=Abraham | url= http://books.google.co.in/books? id=WjvX0HmVTlMC& dq=deadlock+operating+systems& source=gbs_navlinks_s|publisher=Wiley-India| year=2006 | title=Operating System Principles| edition=7 | page=237| accessdate=29 January 2012
Deadlock is a common problem in multiprocessing systems, parallel computing and distributed systems , where software and hardware Lock (computer science)|locks are used to handle shared resources and implement process synchronization .cite book | last=Padua |first= David | url= http://books.google.co.in/books? id=Hm6LaufVKFEC& lpg=PA1749& dq=computer%20networks%20deadlock%20definition& pg=PA524#v=onepage& q=deadlock& f=false|publisher=Springer| year= 2011 | title=Encyclopedia of Parallel Computing| edition= | page=524| accessdate=28 January 2012
In telecommunication systems , deadlocks occur mainly due to lost or corrupt signals instead of resource contention.cite book | last=Schneider | first= G. Michael | url= http://books.google.co.in/books? id=gQK0pJONyhgC& lpg=PA271& dq=deadlock%20signal%20lost& pg=PA271#v=onepage& q=deadlock%20signal%20lost& f=false | publisher= Cengage Learning | year= 2009 | title=Invitation to Computer Science | edition= | page=271| accessdate=28 January 2012
Examples
Deadlock situation can be compared to the classic " chicken or egg " problem.cite book | last=Rolling | first= Andrew | url= http://books.google.co.in/books? id=5SjHsrn_PnUC& lpg=PA421& dq=deadlock%20chicken%20egg& pg=PA421#v=onepage& q=deadlock%20chicken%20egg& f=false | publisher= New Riders | year= 2009 | title=Andrew Rollings and Ernest Adams on game design | edition= | page=421| accessdate=28 January 2012 It can be also considered a paradoxical " Catch-22 (logic)|Catch-22 " situation.cite book | last=Oaks | first=Scott | url= http://books.google.co.in/books? id=mB_92VqJbsMC& lpg=PT82& dq=deadlock%20catch%2022& pg=PT82#v=onepage& q=deadlock%20catch%2022& f=false | publisher= O'Reilly | year= 2004 | title=Java Threads | edition= | page=64| accessdate=28 January 2012 A real world analogical example would be an illogical statute passed by the Kansas legislature in early 20th century, which stated:A Treasury of Railroad Folklore, B.A. Botkin & A.F. Harlow, p. 381 cquote2|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. A simple computer-based example is as follows. Suppose a computer has three CD drives and three processes. Each of the three processes holds one of the drives. If each process now requests another drive, the three processes will be in a deadlock. Each process will be waiting for the "CD drive released" event, which can be only caused by one of the other waiting processes. Thus, it results in a circular reference|circular chain .
Necessary conditions
A deadlock situation can arise if and only if all of the following conditions hold simultaneously in a system:cite book | last=Silberschatz| first=Abraham | url= http://books.google.co.in/books? id=WjvX0HmVTlMC& dq=deadlock+operating+systems& source=gbs_navlinks_s|publisher=Wiley-India| year=2006 | title=Operating System Principles| edition=7 | page=239| accessdate=29 January 2012 # Mutually exclusive events|Mutual Exclusion : At least one resource must be non-shareable. Only one process can use the resource at any given instant of time. # Hold and Wait or Resource Holding: A process is currently holding at least one resource and requesting additional resources which are being held by other processes. # Preemption|No Preemption : The operating system must not de-allocate resources once they have been allocated; they must be released by the holding process voluntarily. # Circular reference|Circular Wait: A process must be waiting for a resource which is being held by another process, which in turn is waiting for the first process to release the resource. In general, there is a set of waiting processes, P = {P1, P2, ..., PN}, such that P1 is waiting for a resource held by P2, P2 is waiting for a resource held by P3 and so on till PN is waiting for a resource held by P1.cite book | last=Shibu | first= | url= http://books.google.co.in/books? id=8hfn4gwR90MC& lpg=PA446& dq=coffman%20deadlock& pg=PA446#v=onepage& q=coffman%20deadlock& f=false | publisher= McGraw Hill Education | year= 2009 | title=Intro To Embedded Systems | edition=1st | page=446| accessdate=28 January 2012
These four conditions are known as the Coffman conditions from their first description in a 1971 article by Edward G. Coffman, Jr. Unfulfillment of any of these conditions is enough to preclude a deadlock from occurring.
Deadlock handling
Most current operating systems cannot prevent a deadlock from occurring.cite book | last=Silberschatz| first=Abraham | url= http://books.google.co.in/books? id=WjvX0HmVTlMC& dq=deadlock+operating+systems& source=gbs_navlinks_s|publisher=Wiley-India | year=2006 | title=Operating System Principles| edition=7 | page=237| accessdate=29 January 2012 When a deadlock occurs, different operating systems respond to them in different non-standard manners. Most approaches work by preventing one of the four Coffman conditions from occurring, especially the fourth one.cite book | last=Stuart | first=Brian L. | url= http://books.google.co.in/books? id=B5NC5-UfMMwC& lpg=PA112& dq=coffman%20conditions& pg=PA112#v=onepage& q=coffman%20conditions& f=false | publisher= Cengage Learning | year= 2008 | title=Principles of operating systems | edition=1st | page=446| accessdate=28 January 2012 Major approaches are as follows.
Ignoring deadlock
In this approach, it is assumed that a deadlock will never occur. This is also an application of the Ostrich algorithm . cite book | last=| first=Andrew S. | url= http://books.google.co.in/books? id=l6sDRvKvCQ0C& lpg=PA177& dq=Tanenbaum%20ostrich& pg=PA177#v=onepage& q& f=false | publisher= Pearson Education | year= 1995 | title=Distributed Operating Systems | edition=1st | page=117| accessdate=28 January 2012 This approach was initially used by MINIX and UNIX . This is used when the time intervals between occurrences of deadlocks is large and the data loss incurred each time is tolerable. It is avoided in very critical systems.
Detection
Under deadlock detection, deadlocks are allowed to occur. Then the state of the system is examined to detect that a deadlock has occurred and subsequently it is corrected. An algorithm is employed that tracks resource allocation and process states, it rolls back and restarts one or more of the processes in order to remove the detected deadlock. Detecting a deadlock that has already occurred is easily possible since the resources that each process has locked and/or currently requested are known to the resource scheduler of the operating system.cite book | last=Tanenbaum | first=Andrew S. | url= http://books.google.co.in/books? id=l6sDRvKvCQ0C& lpg=PA177& dq=Tanenbaum%20ostrich& pg=PA177#v=onepage& q& f=false | publisher= Pearson Education | year= 1995 | title=Distributed Operating Systems | edition=1st | page=118| accessdate=28 January 2012
Deadlock detection techniques include, but are not limited to model checking . This approach constructs a Finite-state machine|finite state -model on which it performs a progress analysis and finds all possible terminal sets in the model. These then each represent a deadlock.
After a deadlock is determined, it can be corrected by using one of the following methods: # Process Termination: One or more process involved in the deadlock may be aborted. We can choose to abort all processes involved in the deadlock. This ensures that deadlock is resolved with certainty and speed. But the expense is high as partial computations will be lost. Or, we can choose to abort one process at a time until the deadlock is resolved. This approach has high overheads because after each abortion an algorithm must detect if the system is still in deadlock. Several factors must be considered while choosing a candidate for termination, such as priority and age of the process. # Resource Preemption: Resource allocated to various processes may be successively preempted and allocated to other processes until deadlock is broken.
Prevention
main|Deadlock prevention algorithmsDeadlock prevention works by preventing one of the four Coffman conditions from occurring.
Removing the mutual exclusion condition means that no process will have exclusive access to a resource. This proves impossible for resources that cannot be Spooling|spooled . But even with spooled resources, deadlock could still occur. Algorithms that avoid mutual exclusion are called non-blocking synchronization algorithms.
The hold and wait or resource holding conditions may be removed by requiring processes to request all the resources they will need before starting up (or before embarking upon a particular set of operations). This advance knowledge is frequently difficult to satisfy and, in any case, is an inefficient use of resources. Another way is to require processes to request resources only when it has none. Thus, first they must release all their currently resources before requesting all the resources they will need from scratch. This too is often impractical. It is so because resource may be allocated and remain unused for long periods. Also, a process requiring a popular resource may have to wait indefinitely as such a process may be always allocated to some process, resulting in resource starvation .cite book | last=Silberschatz| first=Abraham
| url= http://books.google.co.in/books? id=WjvX0HmVTlMC& dq=deadlock+operating+systems& source=gbs_navlinks_s|publisher=Wiley-India| year=2006 | title=Operating System Principles| edition=7 | page=244| accessdate=29 January 2012 (These algorithms, such as serializing tokens , are known as the all-or-none algorithms .)
The no preemption (computing)|preemption condition may also be difficult or impossible to avoid as a process has to be able to have a resource for a certain amount of time, or the processing outcome may be inconsistent or thrashing (computer science)|thrashing may occur. However, inability to enforce preemption may interfere with a priority algorithm. Preemption of a "locked out" resource generally implies a Rollback (data management)|rollback , and is to be avoided, since it is very costly in overhead. Algorithms that allow preemption include lock-free and wait-free algorithms and optimistic concurrency control .
The final condition is the circular wait condition. Approaches that avoid circular waits include disabling interrupts during critical sections and using a hierarchy to determine a partial order ing of resources. If no obvious hierarchy exists, even the memory address of resources has been used to determine ordering and resources are requested in the increasing order of the enumeration. The Dining philosophers problem#Resource_hierarchy_solution|Dijkstra's solution can also be used.
Avoidance
Deadlock can be avoided if certain information about processes are available to the operating system before allocation of resources, such as which resources a process will consume in its lifetime. For every resource request, the system sees if granting the request will mean that the system will enter an unsafe state, meaning a state that could result in deadlock. The system then only grants requests that will lead to safe states.cite book | last=Silberschatz| first=Abraham | url= http://books.google.co.in/books? id=WjvX0HmVTlMC& dq=deadlock+operating+systems& source=gbs_navlinks_s|publisher=Wiley-India| year=2006 | title=Operating System Principles| edition=7 | page=248| accessdate=29 January 2012 In order for the system to be able to determine whether the next state will be safe or unsafe, it must know in advance at any time:
resources currently available
resources currently allocated to each process
resources that will be required and released by these processes in the future
It is possible for a process to be in an unsafe state but for this to not result in a deadlock. The notion of safe/unsafe states only refers to the ability of the system to enter a deadlock state or not. For example, if a process requests A which would result in an unsafe state, but releases B which would prevent circular wait, then the state is unsafe but the system is not in deadlock.
One known algorithm that is used for deadlock avoidance is the Banker's algorithm , which requires resource usage limit to be known in advance. However, for many systems it is impossible to know in advance what every process will request. This means that deadlock avoidance is often impossible.
Two other algorithms are Wait/Die and Wound/Wait, each of which uses a symmetry-breaking technique. In both these algorithms there exists an older process (O) and a younger process (Y). Process age can be determined by a timestamp at process creation time. Smaller timestamps are older processes, while larger timestamps represent younger processes.
!! Wait/ Die !! Wound/ Wait
O needs a resource held by Y
Y needs a resource held by O
Livelock
A livelock is similar to a deadlock, except that the states of the processes involved in the livelock constantly change with regard to one another, none progressing.cite web|url= http://citeseer.ist.psu.edu/326777.html|first=Jeffrey C.|last=Mogul|coauthors=K. K. Ramakrishnan| title=Eliminating receive livelock in an interrupt-driven kernel|year=1996 Livelock is a special case of resource starvation ; the general definition only states that a specific process is not progressing.cite web|url= http://citeseer.ist.psu.edu/anderson01sharedmemory.html| first=James H.|last=Anderson|coauthors=Yong-jik Kim|title=Shared-memory mutual exclusion: Major research trends since 1986|year=2001
A real-world example of livelock occurs when two people meet in a narrow corridor, and each tries to be polite by moving aside to let the other pass, but they end up swaying from side to side without making any progress because they both repeatedly move the same way at the same time.
Livelock is a risk with some algorithms that detect and recover from deadlock. If more than one process takes action, the deadlock detection algorithm can be repeatedly triggered. This can be avoided by ensuring that only one process (chosen randomly or by priority) takes action.cite journal|doi=10.1145/850752.850753|title=The Deadlock problem: a classifying bibliography|first= Dieter|last=Zöbel|journal=ACM SIGOPS Operating Systems Review|volume=17|issue=4|month=October|year= 1983|issn=0163-5980|pages=6–15
Distributed deadlock
Distributed deadlocks can occur in distributed systems when distributed transaction s or concurrency control is being used. Distributed deadlocks can be detected either by constructing a global wait-for graph , from local wait-for graphs at a deadlock detector or by a distributed algorithm like edge chasing .
In a commitment ordering -based distributed environment (including the Two-phase locking#Strong strict two-phase locking|strong strict two-phase locking (SS2PL, or rigorous) special case) distributed deadlocks are resolved automatically by the atomic commit ment protocol (like a two-phase commit (2PC)), and no global wait-for graph or other resolution mechanism is needed. Similar automatic global deadlock resolution occurs also in environments that employ Two-phase locking|2PL that is not SS2PL (and typically not CO; see two-phase locking#Deadlocks in 2PL|Deadlocks in 2PL ). However, 2PL that is not SS2PL is rarely utilized in practice.
Phantom deadlocks are deadlocks that are detected in a distributed system due to system internal delays but no longer actually exist at the time of detection.
See also
Col-beginCol-2
Banker's algorithm
Catch-22 (logic)|Catch 22
Deadlock provision
Dining philosophers problem
File locking
Gridlock|Gridlock (in vehicular traffic)
Hang (computing)|Hang
Impasse
Infinite loop
Col-2
Linearizability
Model checker can be used to formally verify that a system will never enter a deadlock.
cite journal|title=Deadlock Detection in Distributed Object Systems|publisher=University College London|location=London|url= http://www.cs.ucl.ac.uk/staff/w.emmerich/publications/ESEC01/ModelChecking/esec.pdf|first1=Nima|last1=Kaveh|first2=Wolfgang|last2=Emmerich
cite journal|last1=Bensalem|first1=Saddek|first2=Jean-Claude|last2=Fernandez|first3=Klaus|last3= Havelund|first4=Laurent|last4=Mounier|year=2006|title=Confirmation of deadlock potentials detected by runtime analysis|journal=Proceedings of the 2006 workshop on Parallel and distributed systems: Testing and debugging|publisher=ACM|pages=41–50|doi=10.1145/1147403.1147412
cite journal|last1=Mogul|first1=Jeffrey C.|first2=K. K.|last2=Ramakrishnan|year= 1997|title=Eliminating receive livelock in an interrupt-driven kernel|journal=ACM Transactions on Computer Systems|volume=15|issue=3|pages=217–252|issn=07342071|doi=10.1145/263326.263335
cite journal|last=Havender|first=James W.|year=1968|title=Avoiding deadlock in multitasking systems|journal=IBM Systems Journal|volume=7|issue=2|page=74|url= http://domino.research.ibm.com/tchjr/journalindex.nsf/a3807c5b4823c53f85256561006324be/c014b699abf7b9ea85256bfa00685a38? OpenDocument