chapter

    Concurrency, Synchronization and Deadlocks Short Notes for Gate Cs

    Concurrency, Synchronization and Deadlocks short notes for GATE CS: 12 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice

    Concurrency Synchronization and Deadlocks short notes

    Formula matrix

    2 threads, & atomic statements, no cross-constraints.
    threads, statements each, no cross-constraints.
    2 threads, Thread 1's 1st statement fixed at position 1.
    Load Modify Store
    High-level x = x + 1 without explicit atomicity.
    Global vs Local
    Global: single address. Local: independent stack frame per thread.
    Reachability
    Reverse-engineered precedence graph must be acyclic.

    If you see this, do this

    Stem TriggerFirst Move
    "lists all possible combinations"Enumerate valid interleavings preserving intra-thread order.
    "each statement is atomic"Treat each line as indivisible; no load/modify/store splits.
    int local = 0 inside functionIsolate variable; each thread gets independent copy.
    "IMPOSSIBLE to achieve"Reverse-engineer target state; check for cyclic precedence.
    "first statement of Thread X is absolute first"Fix position 1; count interleavings of remaining slots.
    x = x + 1 (no atomicity keyword)Decompose to Load, Modify, Store; check for context switches.
    static int x inside functionTreat as global shared state (data segment), not thread-local.

    Traps and invariants

    Assuming x = x + 1 is atomic. Check: Translate to Load/Modify/Store. If context switch can occur between steps, it is non-atomic.
    Counting interleavings violating intra-thread order. Check: Verify strictly precedes for every thread in the proposed sequence.
    Treating identically named local variables as shared. Check: Check declaration scope. Inside function = independent stack frames per thread.
    Accepting reverse-engineered states with cyclic dependencies. Check: Draw directed edges for required precedence. If a cycle forms, state is impossible.

    9 more cards in this chapter

    Try a question

    Answer it here to see how it works. Nothing is recorded until you sign in.

    Question 1
    Level 1: Warm-up

    Assertion (A): In the bounded buffer problem, if a producer executes wait(mutex) followed by wait(empty), the system may deadlock.

    Reason (R): The producer holds the mutex while blocked on the empty semaphore, preventing the consumer from entering the buffer to free a slot.

    Question 2
    Level 1: Warm-up

    A system has 4 processes, each requiring a maximum of 3 instances of a single resource type. What is the minimum total number of instances of this resource required to guarantee the system is completely deadlock-free?

    Question 3
    Level 1: Warm-up

    A system has processes sharing a single resource type. Each process requires a maximum of 2 instances of this resource. What is the minimum total number of resource instances required to guarantee the system is completely deadlock-free?

    Question 4
    Level 1: Warm-up

    In a system where every resource type has exactly one instance, the Resource Allocation Graph contains a cycle. Which of the following scenarios is IMPOSSIBLE?

    Question 5
    Level 1: Warm-up

    Match the custom locking scheme behaviors (List I) with their corresponding system-level consequences (List II).

    List I

    P: Process terminates the resource holder and restarts it without a priority boost.

    Q: Process acquires a global lock, checks if the resource is free, releases the global lock, and then uses the resource.

    R: Process continuously yields and retries upon lock contention.

    List II

    1: Guarantees mutual exclusion for the resource, but not during the global lock acquisition phase.

    2: Guarantees deadlock freedom, but introduces a risk of starvation.

    3: High CPU utilization with zero system-wide progress (livelock).

    Question 6
    Level 1: Warm-up

    A system uses a terminate-and-restart policy for resource allocation. There are 2 processes, and , and 1 instance of resource .

    • Initially, holds .
    • requests , so is terminated and restarted. now holds .
    • requests , so is terminated and restarted. now holds .
    • requests , so is terminated and restarted. now holds .

    How many distinct processes have been terminated and restarted at least once after this sequence of events?

    Question 7
    Level 1: Warm-up

    A system has two resource types, and , with 1 instance each. Process holds . Process holds .

    requests . The system uses a terminate-and-restart policy: the requester terminates the holder, takes the resource, and restarts the holder.

    After 's request is resolved, immediately requests .

    What is the net change in the total number of resources held by from the initial state to the final state?

    Question 8
    Level 1: Warm-up

    To guarantee that a deadlock is IMPOSSIBLE in a system with processes and a single resource type, what is the minimum number of Coffman conditions that the operating system must strictly negate?

    Question 9
    Level 1: Warm-up

    A system has 3 processes, each requiring a maximum of 4 instances of a single resource type to complete execution. What is the minimum total number of resource instances required to guarantee that the system is completely deadlock-free?

    Question 10
    Level 1: Warm-up

    A system has 3 processes, each requiring a maximum of 4 instances of a single resource type to complete execution. Which of the following statements about the total number of resource instances are correct?

    Free preview ends here

    Login to view the complete short notes

    Creating an account is free. You get the rest of this chapter, step-by-step solutions, and a study plan built around the topics you are actually weak at.

    Explore complete test series, official past papers, and chapter-wise study tools.

    Why MastersUp

    Personalised first. High quality throughout.

    Most platforms hand everyone the same content. Here the content moves with your performance, topic by topic.

    Built around you, not around a syllabus PDF

    Every answer you give moves your topic-level intelligence rate. The next question, the next revision card and tomorrow's plan all change with it.

    Revision that hits your weak spots

    We only revise topics you have actually attempted and are still below the safe bar on — never the same chapter on repeat.

    Questions calibrated to the real exam

    Each question carries a measured toughness. You are served a rung above your current level, so practice keeps stretching you.

    Notes written for recall, not for volume

    Full lesson cards for first study, curated short-note cards for the last mile — with derivations, traps and exam patterns marked.

    One place for everything

    Notes, chapter practice, previous-year questions, test series and full-length papers — all feeding one picture of your preparation.

    Honest progress

    No vanity streaks. Progress here means chapters mastered and accuracy that held up on harder questions.

    Unlock the whole course

    Full notes and short notes, the complete question bank with worked solutions, mock tests, full-length papers, and an adaptive plan that rebuilds itself as you improve.

    Concurrency, Synchronization and Deadlocks Short Notes for GATE CS

    Concurrency, Synchronization and Deadlocks short notes for GATE CS: 12 study cards covering concepts, formulas, shortcuts and exam traps, plus solved practice questions.

    Formula matrix

    2 threads, & atomic statements, no cross-constraints.
    threads, statements each, no cross-constraints.
    2 threads, Thread 1's 1st statement fixed at position 1.
    Load Modify Store
    High-level x = x + 1 without explicit atomicity.
    Global vs Local
    Global: single address. Local: independent stack frame per thread.
    Reachability
    Reverse-engineered precedence graph must be acyclic.

    If you see this, do this

    Stem TriggerFirst Move
    "lists all possible combinations"Enumerate valid interleavings preserving intra-thread order.
    "each statement is atomic"Treat each line as indivisible; no load/modify/store splits.
    int local = 0 inside functionIsolate variable; each thread gets independent copy.
    "IMPOSSIBLE to achieve"Reverse-engineer target state; check for cyclic precedence.
    "first statement of Thread X is absolute first"Fix position 1; count interleavings of remaining slots.
    x = x + 1 (no atomicity keyword)Decompose to Load, Modify, Store; check for context switches.
    static int x inside functionTreat as global shared state (data segment), not thread-local.

    Traps and invariants

    Assuming x = x + 1 is atomic. Check: Translate to Load/Modify/Store. If context switch can occur between steps, it is non-atomic.
    Counting interleavings violating intra-thread order. Check: Verify strictly precedes for every thread in the proposed sequence.
    Treating identically named local variables as shared. Check: Check declaration scope. Inside function = independent stack frames per thread.
    Accepting reverse-engineered states with cyclic dependencies. Check: Draw directed edges for required precedence. If a cycle forms, state is impossible.

    Recall check

    Concurrency, Synchronization and Deadlocks: Solved Questions with Step-by-Step Explanations (10 Problems)

    Question 1 · Operating System MCQ

    Assertion (A): In the bounded buffer problem, if a producer executes wait(mutex) followed by wait(empty), the system may deadlock.

    Reason (R): The producer holds the mutex while blocked on the empty semaphore, preventing the consumer from entering the buffer to free a slot.

    1. A.

      Both A and R are true but R is not the correct explanation of A.

    2. B.

      A is true but R is false.

    3. C.

      Both A and R are true and R is the correct explanation of A.

    4. D.

      A is false but R is true.

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: Acquiring a mutex before checking resource availability can lead to a circular wait if the resource is unavailable.

    Step 1: The producer executes wait(mutex), setting mutex to 0 and acquiring the lock.

    Step 2: The producer then executes wait(empty). If the buffer is full, empty is 0, so the producer blocks.

    Step 3: The producer is now blocked while still holding the mutex.

    Step 4: The consumer needs the mutex to remove an item and signal empty. Since the producer holds the mutex, the consumer blocks forever.

    Step 5: Both processes are blocked, resulting in a deadlock. Thus, both A and R are true, and R correctly explains A.

    Answer: C

    Question 2 · Operating System MCQ

    A system has 4 processes, each requiring a maximum of 3 instances of a single resource type. What is the minimum total number of instances of this resource required to guarantee the system is completely deadlock-free?

    1. A.

      8

    2. B.

      9

    3. C.

      12

    4. D.

      10

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: Use the standard minimum resource formula to break the worst-case deadlock scenario.

    Step 1: Identify the given values. Number of processes . Maximum resources needed per process .

    Step 2: Recall the worst-case scenario for deadlock: every process holds exactly resources and waits for one more.

    Step 3: Calculate the resources tied up in the worst case: .

    Step 4: To guarantee deadlock is broken, add exactly 1 more resource to the system. Total minimum resources = .

    Answer: B

    Question 3 · Operating System MCQ

    A system has processes sharing a single resource type. Each process requires a maximum of 2 instances of this resource. What is the minimum total number of resource instances required to guarantee the system is completely deadlock-free?

    1. A.

    2. B.

    3. C.

    4. D.

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: Apply the standard minimum resource formula to the specific boundary case where .

    Step 1: Identify the given values. Number of processes = . Maximum resources needed per process .

    Step 2: Recall the worst-case scenario formula for deadlock prevention: .

    Step 3: Substitute into the formula: .

    Step 4: Simplify the expression: .

    Answer: B

    Question 4 · Operating System MCQ

    In a system where every resource type has exactly one instance, the Resource Allocation Graph contains a cycle. Which of the following scenarios is IMPOSSIBLE?

    1. A.

      The system is in a deadlock state.

    2. B.

      At least one process is waiting indefinitely.

    3. C.

      A safe sequence of processes exists.

    4. D.

      The circular wait condition is satisfied.

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: In a single-instance resource system, a cycle in the RAG is both necessary and sufficient for deadlock.

    Step 1: The problem states every resource has exactly one instance and a cycle exists.

    Step 2: By the RAG deadlock detection rule for single-instance resources, a cycle guarantees a deadlock.

    Step 3: If the system is deadlocked, no process can finish, meaning no safe sequence can exist.

    Step 4: Therefore, "A safe sequence of processes exists" is impossible.

    Answer: Option C.

    Question 5 · Operating System MCQ

    Match the custom locking scheme behaviors (List I) with their corresponding system-level consequences (List II).

    List I

    P: Process terminates the resource holder and restarts it without a priority boost.

    Q: Process acquires a global lock, checks if the resource is free, releases the global lock, and then uses the resource.

    R: Process continuously yields and retries upon lock contention.

    List II

    1: Guarantees mutual exclusion for the resource, but not during the global lock acquisition phase.

    2: Guarantees deadlock freedom, but introduces a risk of starvation.

    3: High CPU utilization with zero system-wide progress (livelock).

    1. A.

      P-2, Q-1, R-3

    2. B.

      P-1, Q-2, R-3

    3. C.

      P-3, Q-1, R-2

    4. D.

      P-2, Q-3, R-1

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: This is a language-to-math mapping question testing the direct consequences of specific custom locking behaviors.

    Step 1: Behavior P (terminate and restart without priority boost) breaks circular wait, ensuring deadlock freedom, but the restarted process can be targeted again, causing starvation. This maps to 2.

    Step 2: Behavior Q (check and release global lock before use) protects the state transition (checking and marking busy), guaranteeing mutual exclusion for the resource itself, but not for the lock acquisition. This maps to 1.

    Step 3: Behavior R (continuous yield and retry) means processes are actively consuming CPU cycles without making progress, which is the definition of livelock. This maps to 3.

    Answer: P-2, Q-1, R-3, which matches option A.

    Question 6 · Operating System MCQ

    A system uses a terminate-and-restart policy for resource allocation. There are 2 processes, and , and 1 instance of resource .

    • Initially, holds .
    • requests , so is terminated and restarted. now holds .
    • requests , so is terminated and restarted. now holds .
    • requests , so is terminated and restarted. now holds .

    How many distinct processes have been terminated and restarted at least once after this sequence of events?

    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. D.

      0

    Correct Answer:

    B

    Step-by-Step Solution

    Key idea: Track the state of each process and count unique processes that undergo the "terminated and restarted" action.

    Step 1: Initial state: holds . (0 terminations).

    Step 2: requests . is terminated and restarted. ( is now in the terminated count). holds .

    Step 3: requests . is terminated and restarted. ( is now in the terminated count). holds .

    Step 4: requests . is terminated and restarted. ( is terminated again, but already counted). holds .

    Step 5: The distinct processes terminated are and . Total = 2.

    Answer: 2, which matches option B.

    Question 7 · Operating System MCQ

    A system has two resource types, and , with 1 instance each. Process holds . Process holds .

    requests . The system uses a terminate-and-restart policy: the requester terminates the holder, takes the resource, and restarts the holder.

    After 's request is resolved, immediately requests .

    What is the net change in the total number of resources held by from the initial state to the final state?

    1. A.

      -2

    2. B.

      1

    3. C.

      -1

    4. D.

      0

    Correct Answer:

    C

    Step-by-Step Solution

    Key idea: Trace the resource holdings of step-by-step and calculate Final - Initial.

    Step 1: Initial state: holds . Total resources held by = 1.

    Step 2: requests . terminates , takes , and restarts . now holds and . Total = 2.

    Step 3: requests . terminates , takes , and restarts . is restarted and holds 0 resources. Total = 0.

    Step 4: Net change for = Final (0) - Initial (1) = -1.

    Answer: -1, which matches option C.

    Question 8 · Operating System MCQ

    To guarantee that a deadlock is IMPOSSIBLE in a system with processes and a single resource type, what is the minimum number of Coffman conditions that the operating system must strictly negate?

    1. A.

      1

    2. B.

      2

    3. C.

      3

    4. D.

      4

    Correct Answer:

    A

    Step-by-Step Solution

    Key idea: A deadlock can only occur if ALL four Coffman conditions hold simultaneously.

    Step 1: The four Coffman conditions are Mutual Exclusion, Hold and Wait, No Preemption, and Circular Wait.

    Step 2: The logical relationship between these conditions is an AND gate. Deadlock = C1 AND C2 AND C3 AND C4.

    Step 3: To guarantee that deadlock is impossible, the OS only needs to break the AND chain by negating ANY ONE of the conditions.

    Step 4: Therefore, the minimum number of conditions to negate is 1.

    Answer: A

    Question 9 · Operating System NAT

    A system has 3 processes, each requiring a maximum of 4 instances of a single resource type to complete execution. What is the minimum total number of resource instances required to guarantee that the system is completely deadlock-free?

    Correct Answer:

    10.00

    Step-by-Step Solution

    Key idea: Use the worst-case formula for deadlock prevention: .

    Step 1: Identify the number of processes and the maximum resources needed per process .

    Step 2: Calculate the worst-case scenario where every process holds exactly resources without being able to finish. Total tied up = .

    Step 3: Add exactly 1 more resource to break the potential deadlock. This single extra resource can be given to any process, allowing it to reach its maximum of 4, finish, and release all its resources for the others.

    Step 4: Minimum resources = .

    Answer: 10.00

    Question 10 · Operating System MSQ

    A system has 3 processes, each requiring a maximum of 4 instances of a single resource type to complete execution. Which of the following statements about the total number of resource instances are correct?

    1. A.

      The minimum total number of resource instances required to guarantee the system is completely deadlock-free is 10.

    2. B.

      If the system has 9 resource instances, it is guaranteed to be deadlock-free.

    3. C.

      If the system has 12 resource instances, it is guaranteed to be deadlock-free.

    4. D.

      The worst-case scenario ties up exactly 9 resources when every process holds 3 instances.

    Correct Answer:

    ["A","C","D"]

    Step-by-Step Solution

    Key idea: Use the worst-case formula for deadlock prevention: .

    Step 1: Identify processes and maximum resources per process.

    Step 2: Calculate the worst-case tie-up: every process holds resources. Total tied up = . This makes option D true.

    Step 3: Calculate the minimum resources to guarantee deadlock freedom: Worst-case tie-up + 1 = . This makes option A true.

    Step 4: Evaluate option B. With 9 resources, the system is in the exact worst-case scenario, so deadlock is possible, not guaranteed to be free. Option B is false.

    Step 5: Evaluate option C. With 12 resources, every process can get its maximum of 4 simultaneously (), so it is guaranteed to be deadlock-free. Option C is true.

    Answer: A, C, D

    More short notes in this unit