Deadlock Prevention - TarisMajor/5143-OpSystems GitHub Wiki

slide_1

Deadlock prevention is a strategy used in operating systems to ensure that deadlocks do not occur. It involves designing the system in such a way that at least one of the necessary conditions for deadlocks cannot be met, thereby preventing deadlocks from occurring in the first place. Deadlock prevention techniques are proactive and aim to structure resource allocation protocols to avoid circular wait conditions.

Key Characteristics of Deadlock Prevention

  1. Prevention Mechanisms: Various techniques and policies are used to prevent the four necessary conditions for deadlock—mutual exclusion, hold and wait, no preemption, and circular wait.
  2. System Design: Deadlock prevention requires careful system design and resource management to ensure that processes do not enter a deadlocked state.

Four Necessary Conditions for Deadlock

To prevent deadlock, the system must ensure that at least one of the following conditions cannot hold:

  1. Mutual Exclusion: Only one process can hold a resource in non-shareable mode.

    • Prevention: Allow resources to be shared wherever possible. For resources that cannot be shared, ensure exclusive access is carefully managed.
  2. Hold and Wait: Processes holding resources can request additional resources.

    • Prevention: Require processes to request all resources at once, ensuring they do not hold any while waiting for others, or require processes to release all held resources before requesting additional ones.
  3. No Preemption: Resources cannot be forcibly removed from processes holding them.

    • Prevention: Allow preemption of resources. If a process holding some resources requests another resource that cannot be immediately allocated, preempt the currently held resources and allocate them to the requesting process.
  4. Circular Wait: A circular chain of processes exists, where each process holds at least one resource and is waiting to acquire a resource held by the next process in the chain.

    • Prevention: Impose a strict order on resource allocation. Assign a unique priority to each resource type and ensure processes request resources in ascending order of priority.

Advantages of Deadlock Prevention

  1. Proactive Approach: Preventing deadlocks before they occur ensures system stability and avoids the complexities associated with detecting and recovering from deadlocks.
  2. Reliability: Deadlock prevention techniques enhance system reliability by ensuring resources are allocated and managed in a way that prevents process deadlock.
  3. Simpler Recovery: By preventing deadlocks, the system avoids the need for complex recovery mechanisms, which can be difficult to implement and manage.

Disadvantages of Deadlock Prevention

  1. Reduced Resource Utilization: Techniques such as requesting all resources at once or preempting resources can lead to underutilization of system resources.
  2. Complex Implementation: Designing and implementing effective deadlock prevention mechanisms can be complex and require careful planning and analysis.
  3. Potential for Resource Starvation: Some prevention strategies, such as imposing a strict order on resource allocation, may lead to resource starvation for processes that require lower-priority resources.

Use Cases for Deadlock Prevention

  1. Operating Systems: Essential for operating systems that manage multiple processes and resources, ensuring smooth and uninterrupted process execution.
  2. Database Management Systems: Crucial for database systems where transactions may lock resources, leading to potential deadlocks.
  3. Real-Time Systems: Important in real-time systems where predictable and reliable resource allocation is critical for meeting system deadlines.

Sources for Further Reading