The difference between a thread deadlock and hunger

Deadlock: can be considered as two threads or processes request resources other possession.
Starve: a thread waits indefinitely Further two or more threads using mutual transmission and the resource will not be released.

The following four cases will occur deadlock:

  1, are mutually exclusive. A thread or process ever share of shared resources, such as the exclusive resource.

  2, circular wait. For example, in the waiting process A process B, process C process B is waiting, and waiting process C and process A.

  3, partial assignment. Resource allocation is part of, for example, processes A and B need to access a file, a printer at the same time need to use the process to get this file resource A, B process has been printer resources, but the two processes can not get all the resources.

  4, the lack of priority. A process to obtain the resources but has not released the resources, even if the process is in the blocking state.

  According to previous analysis, cases 1 and 4 are threads or processes endless waiting another few resources occupied by threads or processes.

  For several situations that may arise above the deadlock can be given preventive measures, such as controlling thread or process if the judge can not get to all of the resources required, then release the resources already occupied, and so on.

  In reality, when faced with an object to perform multiple actions, and these actions will turn interspersed with

 

 

9. What is Livelock

 

Live like locks and deadlocks like. Just live lock status can be changed. But while the state can change, but no real progress.

For example, two people in a very residential alley. Only once had two people side by side. It polite, must give way to the other side. The results together or let to the left or to the right so that the result is still who can make life difficult. Like standing still or shock state.

Livelock generally due to a deadlock caused by incorrect handling. Due to the deadlock in multiple threads simultaneously took action. The way to avoid this is to have only one thread to release resources.

10. What is starvation.

Starvation (starvation) is a thread prolonged lack of resources needed can not be executed phenomenon. Some people starve to death does not mean that there was a deadlock.

The system also is likely to be good.

Therefore, there is a deadlock and can not just think the system is intact. But also to ensure that the phenomenon does not appear to starve to death.

Avoid starvation should be adopted queue way to ensure that everyone has access to the requested resource. Of course, many ways to implement a change, such as priority, time slice, etc., are "queue" special form

Guess you like

Origin www.cnblogs.com/wzdnwyyu/p/11162985.html