Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Deadlock prevention and deadlock prevention

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

deadlock prevention

To avoid deadlock, one needs to destroy one of the four prerequisites for deadlock occurrence.

1)destroying mutually exclusive premises

If fractional capital is allowed to share, fractional capital will not enter deadlock mode. But some capital basic can not visit at the same time, such as printers and other critical capital can only mutually exclusive use. Therefore, it is not feasible to prevent deadlock by destroying the mutual exclusion premise, and this mutual exclusion should be maintained in some places.

2)destruction without deprivation

When a process which has persisted in certain unsuccessful deprivations of capital, and which has demanded new capital, is not satisfied, it must release all the capital which it has persisted in, and demand it anew when it is demanded. This means that the capital occupied by a process will be temporarily released, perhaps deprived, or thus destroyed.

The strategy is more complex to implement, releasing acquired capital can form the effectiveness of the previous phase of the mission, repeated requests and releases of capital will add piecemeal expenses, reduce piecemeal throughput. This method is often used for forms that are easy to preserve and restore capital, such as CPU storage and memory capital, which cannot be used for capital such as printers.

3)Destroy supplications and insist on premises

The method of static allocation is adopted afterwards, i.e. the process asks for all the capital it needs at once before it runs, and does not put it into operation until its capital is sufficient. Once put into operation, this capital is continuously owned by it, and no other capital is requested, so that the system can be guaranteed against deadlock.

This method is complex, but its defects are self-evident. Fragmented capital is seriously wasted, and some of it can be used only at the beginning of the operation or at the end of the operation, or even at all. It also leads to "starvation," when the process waiting for general capital is delayed in starting to operate because it is temporarily occupied by other processes.

4)Destroy reincarnation waiting for premise

In order to destroy the cyclic waiting premise, sequential capital allocation method can be adopted. First, the number of the capital in the fragment is given, and it is stipulated that each process must request the capital in the order of increasing number, and the capital of the same kind must be requested at once. That is, the process only needs to request allocation capital Ri, and then the process can only request capital with a number greater than Ri in future capital requests.

The problem with this method is that the numbering must fluctuate absolutely, which limits the addition of new types of equipment; although most of the work done in the numbering of capital has been considered to practice the order of the use of these capitals, it often occurs that the order of capital is different from the order of piecemeal rules, resulting in waste of capital; moreover, this method of requesting capital according to the order of rules must also cause trouble to the user's programming.

deadlock prevention

Deadlock prevention is a strategy of prevention in advance, but it is not a prerequisite for destroying deadlocks in advance by some restrictive method, but in the process of static allocation of capital, avoiding fragmentation into unsafe conditions to prevent deadlocks. This approach imposes weaker constraints and allows for better fragmentation.

1. Fragmented peace patterns

Deadlock prevention methods, allowing the process to request capital statically, but before stopping the allocation of capital, we should first consider the safety of the allocation of capital. If the allocation does not result in fragmentation into an unsafe state, allocate capital to the process; otherwise, let the process wait.

The so-called peace form means that fragments can be promoted according to a certain process ( P1, P2,..., Pn), allocating the capital required for each process Pi until the maximum demand for capital for each process is satisfied, so that each process can be completed sequentially. P1, P2,... Pn is the peace sequence. If the fragment cannot find a safe sequence, it is said that the fragment is in an unsafe state.

Suppose there are three processes P1, P2, and P3 in the fragment, for a total of 12 tape drives. Process P1 requires a total of 10 tape drives, P2 and P3 distinguish between 4 and 9 drives. Assume that at time T0, processes P1, P2, and P3 have identified 5, 2, and 2 units, and 3 units have not been assigned, as shown in Table 2-15.

EXHIBIT 2.15 Capital Allocation

Process Max Demand Assigned Available P11053P242

P392

Then at T0 it is safe, since there is a safe sequence P2, P1, P3, i.e. only a piecemeal allocation of capital according to this sequence of processes, then each process can be completed smoothly. If after T0, a tape drive is allocated to P3 in pieces, then the pieces enter an unsafe state at this time, because a safe sequence cannot be found at this time.

Not all unsafe forms are mostly deadlock forms, but when fragments enter unsafe forms, they may enter deadlock forms; conversely, only fragments are in safe forms, and fragments can prevent them from entering deadlock forms.

2. Silver Hand Algorithm

Silver hand algorithm is the most famous deadlock prevention algorithm. The idea it proposes is that the operating fragment is regarded as a silver hand, the capital managed by the operating fragment is equivalent to the funds managed by the silver hand, and the process of requesting the allocation of capital to the operating fragment is equivalent to the deposit of the user to the silver hand. The operating fragment allocates capital to the process according to the rules laid down by the bank, tests the maximum demand of capital by the process when it first requests capital, and allocates capital according to the subsequent demand if the fragment existing capital can meet its maximum demand, otherwise delays the allocation. When the process continues to request capital during performance, test whether the sum of the amount of capital already occupied by the process and the amount of capital requested exceeds the maximum amount of capital required by the process. If it exceeds, the allocation of capital is refused; if it does not exceed, it is tested whether the existing capital in fragments meets the maximum amount of capital still required for the process; if it does, the capital is allocated according to the amount requested later; otherwise, the allocation is postponed.

1)data structure description

Available capital vector: a group of m elements, each element representing the amount of capital available for a class. Available[j]=K, then K existing Rj capital in the representation fragment.

Maximum demand matrix Max: is an n*m matrix, which defines the maximum demand of each of the n processes in the system for m types of capital. Max[i, j]=K, then the maximum amount of capital of class Rj demanded by process i is K.

Allocation matrix: An n*m matrix that defines the amount of capital that each class of capital in the fragment has subsequently allocated to each process. All0Cati0n[i, j]= K, then K is the amount of capital of class Rj that has been allocated since performance process i.

Demand Matrix Need: an n*m matrix representing the amount of capital needed for each process. Need[i, j]=K, then performance process i also requires K capital of class Rj.

These three matrices have the following relationship:

Need[i, j] = Max[i, j] - Allocation[i, j]

2)Silver Hand Algorithm Description

Let Requesti be the request vector of process Pi, and if Requesti[j]K, represent that process Pi requires K capital of class Rj. When Pi recovers the capital request, the fragment stops reflecting at the following pace:

If the request is [j]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report