written 6.0 years ago by | • modified 6.0 years ago |
A deadlock is a situation where in two or more competing actions are each waiting for the other to finish, and thus neither ever does.
In computer science, deadlock refers to a specific condition when two or more processes are each waiting for the other to release a resource, or more than two processes are waiting for resources in a circular chain.
A deadlock, also called as deadly embrace, is a situation in which two threads are each unknowingly waiting for resource held by other.
$\hspace{1.5cm}$ Assume thread/process T1 has exclusive access to resource R1.
$\hspace{1.5cm}$ Thread/ process T2 has exclusive access to resource R2.
$\hspace{1.5cm}$ If T1 needs exclusive access to R2 and T2 needs exclusive access to R1,
$\hspace{1.5cm}$ Neither thread can continue.
$\hspace{1.5cm}$ They are deadlocked.
$\hspace{1.5cm}$ The simplest way to avoid a deadlock is for threads to:
$\hspace{2.5cm}$- Acquire all resources before proceeding
$\hspace{2.5cm}$- Acquire the resources in the same order
$\hspace{2.5cm}$- Release the resource in the revere order
Deadlock is the situation in which multiple concurrent threads of execution in a system are blocked permanently because of resources requirement that can never be satisfied.
A typical real-time system has multiple types of resources and multiple concurrent threads of execution contending for these resources. Each thread of execution can acquire multiple resources of various types throughout its lifetime.
Potential for deadlock exist in a system in which the underlying RTOS permits resources sharing among multiple threads of execution.
Following is a deadlock situation between two tasks.
In this example, process 1 wants the resource 2 ex; scanner while holding the resource 1 ex: printer. Process 1 cannot proceed until both the printer and the scanner are in its possession.
Process 2 wants the printer while holding the scanner. Process 2 cannot continue until it has the printer and the scanner.
Because neither process 1 nor process 2 is willing to give up what it already has, the two tasks are now deadlocked because neither can continue.