Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Deadlock (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Deadlock handling== Most current operating systems cannot prevent deadlocks.<ref>{{cite book|last=Silberschatz|first=Abraham|url=https://books.google.com/books?id=WjvX0HmVTlMC&q=deadlock+operating+systems|publisher=Wiley-India|year=2006|title=Operating System Principles|edition=7|page=237|isbn=9788126509621|access-date=16 October 2020|archive-date=18 April 2021|archive-url=https://web.archive.org/web/20210418013932/https://books.google.com/books?id=WjvX0HmVTlMC&q=deadlock+operating+systems|url-status=live}}</ref> 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.<ref name=pric_os>{{cite book |last=Stuart |first=Brian L. |url=https://books.google.com/books?id=B5NC5-UfMMwC&q=coffman+conditions&pg=PA112 |publisher=Cengage Learning |year=2008 |title=Principles of operating systems |edition=1st |page=446 |isbn=9781418837693 |access-date=16 October 2020 |archive-date=18 April 2021 |archive-url=https://web.archive.org/web/20210418033945/https://books.google.com/books?id=B5NC5-UfMMwC&q=coffman+conditions&pg=PA112 |url-status=live }}</ref> 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]].<ref name="pric_os" /><ref name="distri_tanen">{{cite book |last=Tanenbaum |first=Andrew S. |url=https://books.google.com/books?id=l6sDRvKvCQ0C&q=Tanenbaum+ostrich&pg=PA177 |publisher=Pearson Education |year=1995 |title=Distributed Operating Systems |edition=1st |page=117 |isbn=9788177581799 |access-date=16 October 2020 |archive-date=18 April 2021 |archive-url=https://web.archive.org/web/20210418011235/https://books.google.com/books?id=l6sDRvKvCQ0C&q=Tanenbaum+ostrich&pg=PA177 |url-status=live }}</ref> This approach was initially used by [[MINIX]] and [[UNIX]].<ref name="embb"/> This is used when the time intervals between occurrences of deadlocks are large and the data loss incurred each time is tolerable. Ignoring deadlocks can be safely done if deadlocks are [[formal verification|formally proven]] to never occur. An example is the RTIC framework.<ref>{{Cite web|url=https://rtic.rs/0.5/book/en/|title=Preface - Real-Time Interrupt-driven Concurrency|access-date=1 October 2020|archive-date=18 September 2020|archive-url=https://web.archive.org/web/20200918143731/https://rtic.rs/0.5/book/en/|url-status=live}}</ref> ===Detection=== Under the 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 [[Scheduler (computing)|resource scheduler]] of the operating system.<ref name=distri_tanen /> After a deadlock is detected, it can be corrected by using one of the following methods:{{Citation needed|date=May 2016}} # ''Process termination:'' one or more processes involved in the deadlock may be aborted. One could choose to abort all competing [[Process (computing)|processes]] involved in the deadlock. This ensures that deadlock is resolved with certainty and speed.{{Citation needed|date=May 2016}} But the expense is high as partial computations will be lost. Or, one could choose to abort one process at a time until the deadlock is resolved. This approach has a high overhead because after each abort an algorithm must determine whether the system is still in deadlock.{{Citation needed|date=May 2016}} Several factors must be considered while choosing a candidate for termination, such as priority and age of the process.{{Citation needed|date=May 2016}} # ''Resource preemption:'' resources allocated to various processes may be successively preempted and allocated to other processes until the deadlock is broken.<ref>{{cite web|url=https://www.ibm.com/support/knowledgecenter/SSETD4_9.1.2/lsf_admin/resource_preemption_about.html|title=IBM Knowledge Center|website=www.ibm.com|access-date=29 April 2018|url-status=live|archive-url=https://web.archive.org/web/20170319112925/https://www.ibm.com/support/knowledgecenter/SSETD4_9.1.2/lsf_admin/resource_preemption_about.html|archive-date=19 March 2017}}</ref>{{Failed verification|date=December 2021}} ===Prevention=== {{main|Deadlock prevention algorithms}} [[File:Avoiding deadlock.gif|380px|thumbnail|right| (A) Two processes competing for one resource, following a first-come, first-served policy. (B) Deadlock occurs when both processes lock the resource simultaneously. (C) The deadlock can be ''resolved'' by breaking the symmetry of the locks. (D) The deadlock can be ''prevented'' by breaking the symmetry of the locking mechanism.]] Deadlock 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, the 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; First, they must release all their currently held resources before requesting all the resources they will need from scratch. This too is often impractical. It is so because resources may be allocated and remain unused for long periods. Also, a process requiring a popular resource may have to wait indefinitely, as such a resource may always be allocated to some process, resulting in [[resource starvation]].<ref>{{cite book|last=Silberschatz|first=Abraham|url=https://books.google.com/books?id=WjvX0HmVTlMC&q=deadlock+operating+systems|publisher=Wiley-India|year=2006|title=Operating System Principles|edition=7|page=244|isbn=9788126509621|access-date=16 October 2020|archive-date=18 April 2021|archive-url=https://web.archive.org/web/20210418013932/https://books.google.com/books?id=WjvX0HmVTlMC&q=deadlock+operating+systems|url-status=live}}</ref> (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, the 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]]. If a process holding some resources and requests for some another resource(s) that cannot be immediately allocated to it, the condition may be removed by releasing all the currently being held resources of that process. * 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.<ref name="os_galvin"/> [[Dining philosophers problem#Resource hierarchy solution|Dijkstra's solution]] can also be used. ===Deadlock avoidance=== Similar to deadlock prevention, deadlock avoidance approach ensures that deadlock will not occur in a system. The term "deadlock avoidance" appears to be very close to "deadlock prevention" in a linguistic context, but they are very much different in the context of deadlock handling. Deadlock avoidance does not impose any conditions as seen in prevention but, here each resource request is carefully analyzed to see whether it could be safely fulfilled without causing deadlock. Deadlock avoidance requires that the operating system be given in advance additional information concerning which resources a process will request and use during its lifetime. Deadlock avoidance algorithm analyzes each and every request by examining that there is no possibility of deadlock occurrence in the future if the requested resource is allocated. The drawback of this approach is its requirement of information in advance about how resources are to be requested in the future. One of the most used deadlock avoidance algorithms is [[Banker's algorithm]].<ref>{{Cite web|url=https://www.electronicsmind.com/2022/01/deadlock-avoidance-algorithms-in-operating-system.html|title=Deadlock Avoidance Algorithms in Operating System (OS)|date=26 January 2022|website=Electronics Mind}}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)