Synchronization and Deadlocks

Synchronization coordinates concurrent access to shared data using locks, semaphores and monitors; deadlock arises when all four Coffman conditions hold, and is handled by prevention, avoidance (Banker’s algorithm), detection or recovery.

Key formulas & points

Skim these first — then read the full notes below.

  • Mutex versus binary semaphore; counting semaphores manage pools
  • Deadlock prevention breaks one Coffman condition
  • A monitor is a high-level lock plus condition variables

Topic details

Introduction

This Galvin topic covers concurrency control. You solve critical-section problems with semaphores and monitors, reason about the four necessary conditions for deadlock, apply the Banker’s algorithm for avoidance, and compare prevention, detection and recovery strategies.

Key relations & formulas

Formulas (Indian textbook notation)

  • fourCoffmanconditions:mutualexclusion,holdandwait,nopreemption,circularwaitfour Coffman conditions: mutual exclusion, hold-and-wait, no preemption, circular wait

Formulas (Indian textbook notation)

  • BankersalgorithmgrantsarequestonlyifasafesequencestillexistsBanker's algorithm grants a request only if a safe sequence still exists

Formulas (Indian textbook notation)

  • semaphore:waitPdecrements,signalVincrementssemaphore: \frac{wait}{P} decrements, \frac{signal}{V} increments

Notation and sign conventions

Relation 1 —
fourCoffmanconditions:mutualexclusion,holdandwait,nopreemption,circularwaitfour Coffman conditions: mutual exclusion, hold-and-wait, no preemption, circular wait

Formulas (Indian textbook notation)

  • fourCoffmanconditions:mutualexclusion,holdandwait,nopreemption,circularwaitfour Coffman conditions: mutual exclusion, hold-and-wait, no preemption, circular wait
Write this relation with symbols exactly as in Operating System Concepts — Silberschatz, Galvin & Gagne before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 2 —
BankersalgorithmgrantsarequestonlyifasafesequencestillexistsBanker's algorithm grants a request only if a safe sequence still exists

Formulas (Indian textbook notation)

  • BankersalgorithmgrantsarequestonlyifasafesequencestillexistsBanker's algorithm grants a request only if a safe sequence still exists
Write this relation with symbols exactly as in Operating System Concepts — Silberschatz, Galvin & Gagne before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.
Relation 3 —
semaphore:waitPdecrements,signalVincrementssemaphore: \frac{wait}{P} decrements, \frac{signal}{V} increments

Formulas (Indian textbook notation)

  • semaphore:waitPdecrements,signalVincrementssemaphore: \frac{wait}{P} decrements, \frac{signal}{V} increments
Write this relation with symbols exactly as in Operating System Concepts — Silberschatz, Galvin & Gagne before substituting numbers. Examiners award partial marks for a correct setup even when arithmetic slips.

Concept in depth

When threads share data, uncontrolled interleaving causes race conditions, so mutual exclusion protects the critical section — semaphores (a counter with atomic wait/signal) and monitors (language-level locks with condition variables) provide it. But locking introduces deadlock: if processes hold resources while waiting for others in a cycle, and none will preempt, everyone blocks forever. All four Coffman conditions must hold simultaneously, so breaking any one prevents deadlock. Avoidance instead stays in safe states — the Banker’s algorithm grants a resource only if a sequence exists in which every process can still finish. Detection lets deadlock happen and then recovers by aborting or preempting.

Assumptions and validity limits

State assumptions explicitly before using any relation for synchronization and deadlocks — steady state, uniform properties, linear elastic material, ideal gas, incompressible flow, etc., as applicable.
Wrong assumptions invalidate the entire solution even when the formula is correct. In Operating Systems viva and GATE descriptive questions, listing valid assumptions often earns separate marks.

Step-by-step problem approach

1. Read the question and list given data with SI units (common in Operating Systems papers).
2. Draw a neat labelled diagram where applicable — examiners in Indian universities award diagram marks even when arithmetic slips.
3. Identify which relation from this topic applies to synchronization and deadlocks.
4. Use equation 1:
fourCoffmanconditions:mutualexclusion,holdandwait,nopreemption,circularwaitfour Coffman conditions: mutual exclusion, hold-and-wait, no preemption, circular wait
.
5. Use equation 2:
BankersalgorithmgrantsarequestonlyifasafesequencestillexistsBanker's algorithm grants a request only if a safe sequence still exists
.
6. Substitute values, compute, and verify units and sign (direction).
7. State conclusion in one line — e.g. safe/unsafe, stable/unstable, feasible/infeasible.

Applications & exam relevance

Synchronization and Deadlocks appears in systems software and backend. In Indian it software curricula this topic is tested because it connects theory to process, memory, and file management.
GATE and semester exams often combine synchronization and deadlocks with earlier units — revise prerequisites before attempting mixed problems.
Industry interview panels sometimes ask: "Where did you use synchronization and deadlocks?" — answer with a lab, mini-project, or plant visit example if possible.

Common mistakes in exams

Students break only some Coffman conditions and still expect deadlock (all four are needed together), misapply the Banker’s algorithm by not checking for a safe sequence, and confuse a mutex (ownership) with a counting semaphore. Forgetting that a semaphore’s wait/signal must be atomic leads to wrong reasoning.

Quick revision checklist

Before attempting synchronization and deadlocks problems, confirm you can:
1. Mutex versus binary semaphore; counting semaphores manage pools
2. Deadlock prevention breaks one Coffman condition
3. A monitor is a high-level lock plus condition variables
Revise the solved examples in Operating System Concepts — Silberschatz, Galvin & Gagne and one previous-year GATE or university paper for this unit.

Worked examples

Try the problem first — open the solution when you are ready to check.

Deadlock condition check

Problem

A system uses lock ordering so every process acquires locks in the same global order. Which Coffman condition does this break?

Solution

It breaks circular wait: a consistent global acquisition order makes a cycle of waiting impossible, so deadlock cannot form even though the other three conditions may hold.

Conceptual check — Synchronization and Deadlocks

Problem

In a Operating Systems semester or GATE paper you are asked: "State the main assumption, the governing relation, and one practical consequence of synchronization and deadlocks." What should a complete answer include?

📖 Standard books (India)

  • Operating System ConceptsSilberschatz, Galvin & Gagne

    Read: Syllabus unit

    Processes, memory, and file systems