Comprehensive Deadlock Handling Strategies
The comprehensive deadlock handling strategy is to adopt the most appropriate deadlock handling strategy according to different resource types, so as to avoid deadlock while ensuring the efficient operation of the system. This strategy usually considers the characteristics of different resources in the system and the needs of processes, and adopts different resource management and deadlock handling methods. The following are specific strategies for several types of resources:
Swapable space (for example: auxiliary storage blocks)
- Strategy: You can adopt deadlock prevention, requiring the process to allocate all required resources at once at the beginning. This is similar to the "hold and wait" deadlock prevention method, where all the maximum possible storage requirements are applied and obtained when the process starts, avoiding requesting resources during the operation.
- Applicable situations: This method is effective and reasonable when the maximum storage requirement of the process is known (usually known).
- Deadlock avoidance: If the system knows the maximum requirement of each process, deadlock avoidance strategies (such as the banker's algorithm) can also be used.
Process resources (for example: tape devices, files, etc.)
- Strategy: For process resources, deadlock avoidance is usually very effective. Because processes can declare the resources they need before running, the system can allocate resources in advance based on these declarations.
- Resource sorting: You can use the resource sorting prevention strategy to ensure that processes will not cause deadlock when applying for resources in order. That is, the system assigns a sequence number to each resource, and the process must apply for resources in the order of the resource sequence number to avoid circular waiting.
Main memory (for example: memory allocation by page or segment)
- Strategy: For main memory, it is most appropriate to adopt the preemption-based prevention strategy. When a process cannot continue to execute due to lack of sufficient memory resources, the system can choose to preempt the current process and swap its content to auxiliary memory (disk) to free up main memory space in order to resolve deadlock.
- Preemption: This strategy means that when system resources are insufficient, the executing process may be interrupted, and resources will be recycled and allocated to other processes. This method reduces the risk of deadlock, but requires the system to support process swap operations.
Internal resources (e.g. I/O channels, etc.)
- Strategy: For internal resources, you can use prevention strategy based on resource ordering. Similar to the strategy for process resources, it requires processes to apply for and release resources in a specific order to avoid deadlock loop waiting.
- Resource ordering: This strategy requires the system to sort resources, and processes can only apply for and release resources in the order of resources, thus ensuring that deadlock does not occur.