api: YAML JSON TOON Database
version: 1.0.0
format: yaml
dataset:
  id: 2778
  slug: deadlock-handling
  title: Deadlock Handling
  description: Conditions and strategies for dealing with deadlocks.
  summary: The four necessary conditions for deadlock, the strategies for dealing with it (prevention, avoidance, detection and recovery) and related hazards such as livelock and starvation. Each entry is a one-line definition suitable for exam review or design discussion.
  use_when:
    - You are diagnosing a hang and need the vocabulary for what is happening.
    - You are choosing between preventing deadlock and detecting it.
  caveats:
    - Most general-purpose operating systems do not prevent deadlock for user programs; they leave it to application design.
    - Banker's algorithm needs advance knowledge of maximum resource needs, which is rarely available.
  related:
    - process-management
    - cpu-scheduling-algorithms
    - memory-management
  entry_count: 15
  fields:
    - section: data
      field: concept
      type: string
      example: Mutual Exclusion
    - section: data
      field: description
      type: string
      example: At least one resource must be non-sharable.
  category: Operating Systems
  category_slug: operating-systems
  tags: os,deadlock,concurrency
  view_count: 41
  created_at: 1793403093
  updated_at: 1793403093
data:
  - concept: Mutual Exclusion
    description: At least one resource must be non-sharable.
  - concept: Hold and Wait
    description: A process holds resources while waiting for additional ones.
  - concept: No Preemption
    description: Resources cannot be forcibly taken from a process.
  - concept: Circular Wait
    description: A circular chain of processes each waiting for a resource held by the next.
  - concept: Banker's Algorithm
    description: Deadlock avoidance using safety checks on resource allocation.
  - concept: Deadlock Prevention
    description: Design the system so at least one necessary condition cannot hold.
  - concept: Deadlock Detection
    description: Periodically check the resource allocation graph for cycles.
  - concept: Resource Allocation Graph
    description: A directed graph of processes and resources; a cycle indicates possible deadlock, and certain deadlock when each resource has a single instance.
  - concept: Safe State
    description: A state in which there is an order in which every process can finish even if all request their maximum needs.
  - concept: Deadlock Avoidance
    description: Granting a request only if the resulting state remains safe, as the Banker's algorithm does.
  - concept: Deadlock Recovery
    description: Breaking a detected deadlock by terminating processes or preempting resources.
  - concept: Lock Ordering
    description: Requiring all code to acquire locks in one global order, which removes circular wait.
  - concept: Livelock
    description: Processes keep changing state in response to each other but make no progress.
  - concept: Starvation
    description: A process waits indefinitely because others are always favored; aging is a common remedy.
  - concept: Ostrich Algorithm
    description: Ignoring deadlock on the assumption that it is rare and the cost of handling it is not worth paying.
