Deadlock

What is deadlock?

Deadlock is a permanent blocking of a set of processes that either compete for system resources or communicate with each other. A set of processes is blocked awaiting an event that can only be triggered by another blocked process in the set. The Deadlock is permanent and don have any efficient solution.

Example of deadlock


There are 2 process P and Q compete for resources A and B. Each resource only can use by 1 process.The process P get and hold the resource B and wait the resource A available , at the same time the process Q get and hold the resource A while waiting resource B available. And this condition it cause deadlock because both process need use resource A and B at the same time, the process P not willing to let go the resource B same as the process Q.

Some time we also use the Joint Progress Diagram to illustrate the two process competing the resource. In the joint progress diagram we have 6 path of process Q and P get resources:

  1. Process Q get B,get A then release B and after that release A
  2. Process Q get B,get A then the process P want to get A but since Q hold it then have to wait Q finish then Q release B and A.
  3. Process Q get resource B and the process P get resource A. --> deadlock
  4. Process P get resource A and the process Q get resource B --> deadlock
  5. Process P get A and get b, then the process Q try to get B but since P hold B then wait process P finish
  6.  Process P get A,get B then release A and after that release B

Joint Progress Diagram

Categories of Resource


Two general categories of resources can be distinguished: reusable and consumable. A reusable resource is one that can be safely used by only one process at a time and is not depleted by that use. Processes obtain resource units that they later release for reuse by other processes. Examples of reusable resources include processors; I/O channels; main and secondary memory; devices; and data structures such as files, databases, and semaphores.



Deadlock is quite a big topic, I will try to separate the deadlock condition and solving approach at another posts.

Condition for deadlock
There are 4 condition of deadlock which are:
  1. Mutual Exclusion
  2. Hold and Wait
  3. No preemption
  4. Circular Wait
Approach to solve/avoid Deadlock
There are 3 approach which are:
  1. Deadlock Prevention
  2. Deadlock Avoidance
  3. Deadlock Detection

Comments

Popular posts from this blog

Reading and Writing Operation of SRAM

Transmission Control Protocol (TCP)

File transfer from android to linux