What are the 4 types of deadlock?

Deadlocks in operating systems can be classified based on the type of resources and the situations causing them. Here are the four main types of deadlock:

1. Resource Deadlock

This occurs when processes compete for non-shareable resources and hold them while waiting for additional resources.

Example

  • Process A holds Resource X and requests Resource Y.
  • Process B holds Resource Y and requests Resource X.
  • Both processes are stuck, waiting indefinitely.

Key Features

  • Involves physical or logical resources (e.g., files, memory, printers).
  • Results from circular wait and hold-and-wait conditions.

2. Communication Deadlock

This type arises when processes are waiting for messages or signals from each other to proceed, but none can send or receive due to cyclic dependencies.

Example

  • Process A waits for a message from Process B.
  • Process B waits for a message from Process A.
  • Neither process progresses.

Key Features

  • Involves inter-process communication (IPC) mechanisms.
  • Common in distributed systems and message-passing scenarios.

3. Thread Deadlock

Occurs in multithreading environments when threads within a single process block each other by competing for shared resources.

Example

  • Thread 1 locks Resource X and waits for Resource Y.
  • Thread 2 locks Resource Y and waits for Resource X.

Key Features

  • Involves synchronization issues with mutexes, semaphores, or locks.
  • Common in applications using multithreading.

4. Circular Wait Deadlock

This is a generic form where a cycle of processes exists, and each process is waiting for a resource held by the next process in the cycle.

Example

  • Process A → waits for Resource X held by Process B.
  • Process B → waits for Resource Y held by Process C.
  • Process C → waits for Resource Z held by Process A.

Key Features

  • A direct result of the circular wait condition.
  • Often resolved by breaking the circular dependency.

How to Prevent or Handle Deadlocks

  • Avoidance Techniques: Use algorithms like the Banker's Algorithm to allocate resources safely.
  • Prevention Strategies: Remove one of the four necessary conditions for deadlocks.
  • Detection and Recovery: Periodically check for deadlocks and resolve them by terminating or rolling back processes.

For a deeper understanding of deadlocks and practical ways to handle them, check out Grokking Multithreading and Concurrency for Coding Interviews. This will help you master synchronization issues and deadlock management in both interviews and real-world applications.

TAGS
Coding Interview
System Design Interview
CONTRIBUTOR
Arslan Ahmad
Arslan Ahmad
ex-FAANG engineering manager and author or Grokking series.
-

GET YOUR FREE

Coding Questions Catalog

Design Gurus Newsletter - Latest from our Blog
Boost your coding skills with our essential coding questions catalog.
Take a step towards a better tech career now!
Explore Answers
What is the += in C++?
What are the 5 rounds of Google interview?
What is the salary of backend engineer in Stripe?
What every success story starts with?
Why do I never pass interviews?
What is the youngest age to get an internship?
Related Courses
New
Grokking the AI System Design Interview course cover
Grokking the AI System Design Interview
Learn to design AI systems the way interviewers expect: classic ML products, LLM and RAG architectures, and agentic systems, all through the lens of the system design interview.
4.6
(3,192 learners)
Discounted price for Your Region

$123

Grokking the Coding Interview: Patterns for Coding Questions course cover
Grokking the Coding Interview: Patterns for Coding Questions
The 24 essential patterns behind every coding interview question. Available in Java, Python, JavaScript, C++, C#, and Go. The most comprehensive coding interview course with 543 lessons. A smarter alternative to grinding LeetCode.
4.6
Discounted price for Your Region

$197

Grokking Modern AI Fundamentals course cover
Grokking Modern AI Fundamentals
Master the fundamentals of AI today to lead the tech revolution of tomorrow.
4.1
Discounted price for Your Region

$72

Design Gurus logo
One-Stop Portal For Tech Interviews.
Copyright © 2026 Design Gurus, LLC. All rights reserved.