What is a deadlock? If every process in a process set is waiting for an event that can only be triggered by another process in the Set (including itself), this situation is a deadlock.
This definition may be a bit confusing. One of the simplest examples is resource A and resource B, which are both uneconomical resources. Now process C has applied for resource, process D also applies for resource B. The next operation of Process C requires resource B, and process D also applies for resource A, which causes a deadlock. This must have been viewed by everyone. Apply back to the definition: if every process (Process C and process D) in a process set (Process C and process D) all are waiting for only one other process in this set (for Process C, he is waiting for process D; for process D, he is waiting for Process C) events that can be triggered (resources are released ).
Resources here include soft resources (code blocks) and hard resources (such as scanners ). There are two types of resources: preemptable and nonpreemptable ). Generally, the deadlock caused by Resource deprivation can be solved by the re-allocation of resources by the system. Generally, the deadlock is caused by the unavailability of resources.
Four Conditions for deadlock
Mutual Exclusion: resources cannot be shared and can only be used by one process.
Hold and wait: processes that have obtained resources can apply for new resources again.
No pre-emption: allocated resources cannot be forcibly deprived from the corresponding process.
Loop wait condition (circular wait): several processes in the system form a loop in which each process is waiting for resources occupied by adjacent processes.
Deadlock Handling Policy
1. ignore this issue. For example, the ostrich algorithm can be applied in rare cases of deadlocks. Why is it called the ostrich algorithm? Because it is said that an ostrich will bury its head under the ground when it sees danger. Maybe the ostrich will feel no danger if it does not. It is a bit like a hacker.
2. Check the deadlock and restore it.
3. Carefully allocate resources dynamically to avoid deadlocks.
4. Avoid deadlock by breaking one of the four conditions.