---
title: "Deadlock and Coffman conditions"
subject: "Embedded System"
chapter: 6
key: "semester_6/embedded_system:coffman-deadlock"
source: https://www.bctengineer.com/q/semester_6/embedded_system/coffman-deadlock
site: BCT Engineering
---

# Deadlock and Coffman conditions

Embedded System · Chapter 6: RTOS

- Asked in: 2073 Bhadra, 4 marks; 2070 Bhadra, 3 marks; 2075 Bhadra, 2 marks; 2078 Chaitra (asked 4 times)
- Video: [L-4.1: DEADLOCK concept | Example | Necessary condition | Operating System](https://www.youtube.com/watch?v=rWFH6PLOIEI) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/coffman-deadlock
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-6

## Question

Define deadlock and explain the Coffman conditions (conditions favoring deadlock).

## Short answer

Deadlock is a cycle of tasks each holding a resource and waiting for another held within the set. The four necessary Coffman conditions are mutual exclusion, hold-and-wait, no preemption, and circular wait. All must hold for deadlock to occur.

## Answer

A **deadlock** is a situation in which two or more tasks (processes) are each waiting for a resource held by another in the set, so none of them can proceed. Example: task T1 holds resource R1 and waits for R2, while T2 holds R2 and waits for R1.

```text
   T1 --holds--> R1 <--waits-- T2
   T1 --waits--> R2 --held by-- T2
```

#### Coffman conditions
Deadlock can occur only if all four hold at the same time:
1. **Mutual exclusion:** at least one resource can be used by only one task at a time (non-shareable).
2. **Hold and wait:** a task holds at least one resource while waiting for additional resources held by others.
3. **No pre-emption:** a resource cannot be forcibly taken from a task; the task must release it voluntarily.
4. **Circular wait:** there is a closed chain of tasks, each waiting for a resource held by the next one in the chain.

**Handling:** prevent by removing any one condition (e.g. request all resources at once, impose a resource ordering), avoid (Banker's algorithm), detect and recover, or ignore.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is a deadlock?
   A. A task using too much memory
   B. Tasks each waiting for a resource held by another, so none can proceed
   C. A crashed ISR
   D. A task running forever without waiting
   Answer: B. For example, T1 holds R1 and waits for R2 while T2 holds R2 and waits for R1. (Key point: Definition of deadlock)

2. Which set lists all four Coffman conditions?
   A. Mutual exclusion, starvation, pre-emption, race
   B. Mutual exclusion, hold and wait, no pre-emption, circular wait
   C. Race, critical section, no pre-emption, starvation
   D. Hold and wait, priority inversion, circular wait, aging
   Answer: B. All four must hold at the same time for deadlock. (Key point: Coffman conditions)

3. What does the 'no pre-emption' condition mean?
   A. Interrupts are disabled
   B. Resources are shareable
   C. A resource cannot be forcibly taken; the task releases it voluntarily
   D. Tasks cannot be scheduled
   Answer: C. Resources are released only voluntarily. (Key point: No pre-emption)

4. How can deadlock be prevented?
   A. Increase priority of all tasks
   B. Disable the scheduler
   C. Remove any one of the four conditions, e.g. request all resources at once or impose ordering
   D. Add more tasks
   Answer: C. Breaking any one Coffman condition prevents deadlock. (Key point: Prevention)

## Related in other subjects

- [Deadlock and its conditions](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Adeadlock-conditions) — Microprocessor, chapter 6, asked 2×
- [Deadlock; necessary conditions with examples](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-necessary-conditions-examples) — Operating System, chapter 7
- [Deadlock conditions; Banker's with 4 processes](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afour-conditions-banker-p1-p4) — Operating System, chapter 7
- [Deadlock conditions and why all necessary](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-why-necessary) — Operating System, chapter 7
