Deadlock "The difference between mutually exclusive and inalienable conditions"

Four necessary conditions for deadlock

Mutually exclusive conditions

The process requires control of the allocated resources (such as printers) 排他性, that is, a certain resource is only occupied by one process in a period of time. If another process requests the resource at this time, the requesting process can only wait.

Inalienable condition

The resources obtained by a process cannot be forcibly taken away by other processes before being used up, that is, the process that obtains the resource can only release it by itself (only active release).

Keep and request conditions

The process has maintained at least one resource, but has made a new resource request, and the resource is already occupied by other processes. At this time, the requesting process is blocked, but keeps holding on to the resources it has obtained.

Loop waiting condition

There is a cyclic waiting chain of process resources, and the resources acquired by each process in the chain are simultaneously requested by the next process in the chain.

That is, there is a set of processes in the waiting state {Pl, P2, …, pn}, where Pi is waiting for resources occupied by P(i+1) (i=0, 1, …, n-1), Pn waiting for resources Occupied by P0.

The difference between mutually exclusive and inalienable conditions

These two concepts relatively easily confused, here to talk about individuals 互斥and 不可剥夺understanding.

Mutual exclusion : For example, the positive and negative poles of a magnet are mutually exclusive. There is no intermediate pole, either the positive pole or the negative pole. The mutual exclusion here is also similar, that is, a resource can only be occupied by one thread at the same time, which is like an iron block between two positive and negative magnets. No matter how you operate, when you let go, it will definitely add to it. One side moves closer, it is impossible to be in the middle position.

Inalienable : Inalienable means that a thread holds a resource, and other threads can only wait before it releases the resource.

The difference between the two is :

  1. Mutual exclusion is from the perspective of resources, and inalienability is from the perspective of threads.

  2. Mutual exclusion emphasizes number, and inalienable emphasis is time.

  3. The two emphasized that the occurrence time is different: the
    互斥emphasis is that when a resource is competed by multiple threads at the same time; the
    不可剥夺emphasis is that a resource has been successfully preempted by a thread, and it occurs during the holding period.

Guess you like

Origin blog.csdn.net/weixin_44471490/article/details/108975335