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
(mm+n)
2 threads, m & n atomic statements, no cross-constraints.
∏ni!(∑ni)!
k threads, ni statements each, no cross-constraints.
(m−1N−1)
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.
Treat each line as indivisible; no load/modify/store splits.
int local = 0 inside function
Isolate 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 N−1 slots.
x = x + 1 (no atomicity keyword)
Decompose to Load, Modify, Store; check for context switches.
static int x inside function
Treat 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 Si strictly precedes Si+1 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 N 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, P1 and P2, and 1 instance of resource R.
Initially, P1 holds R.
P2 requests R, so P1 is terminated and restarted. P2 now holds R.
P1 requests R, so P2 is terminated and restarted. P1 now holds R.
P2 requests R, so P1 is terminated and restarted. P2 now holds R.
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, R1 and R2, with 1 instance each. Process PA holds R1. Process PB holds R2.
PA requests R2. The system uses a terminate-and-restart policy: the requester terminates the holder, takes the resource, and restarts the holder.
After PA's request is resolved, PB immediately requests R1.
What is the net change in the total number of resources held by PA 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 N 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.
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
(mm+n)
2 threads, m & n atomic statements, no cross-constraints.
∏ni!(∑ni)!
k threads, ni statements each, no cross-constraints.
(m−1N−1)
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.
Treat each line as indivisible; no load/modify/store splits.
int local = 0 inside function
Isolate 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 N−1 slots.
x = x + 1 (no atomicity keyword)
Decompose to Load, Modify, Store; check for context switches.
static int x inside function
Treat 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 Si strictly precedes Si+1 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 SystemMCQ
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.
A.
Both A and R are true but R is not the correct explanation of A.
B.
A is true but R is false.
C.
Both A and R are true and R is the correct explanation of A.
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 SystemMCQ
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?
A.
8
B.
9
C.
12
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 N=4. Maximum resources needed per process M=3.
Step 2: Recall the worst-case scenario for deadlock: every process holds exactly M−1 resources and waits for one more.
Step 3: Calculate the resources tied up in the worst case: N×(M−1)=4×(3−1)=4×2=8.
Step 4: To guarantee deadlock is broken, add exactly 1 more resource to the system. Total minimum resources = 8+1=9.
Answer: B
Question 3 · Operating SystemMCQ
A system has N 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?
A.
N
B.
N+1
C.
2N
D.
2N−1
Correct Answer:
B
Step-by-Step Solution
Key idea: Apply the standard minimum resource formula to the specific boundary case where M=2.
Step 1: Identify the given values. Number of processes = N. Maximum resources needed per process M=2.
Step 2: Recall the worst-case scenario formula for deadlock prevention: k=N(M−1)+1.
Step 3: Substitute M=2 into the formula: k=N(2−1)+1.
Step 4: Simplify the expression: k=N(1)+1=N+1.
Answer: B
Question 4 · Operating SystemMCQ
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?
A.
The system is in a deadlock state.
B.
At least one process is waiting indefinitely.
C.
A safe sequence of processes exists.
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 SystemMCQ
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).
A.
P-2, Q-1, R-3
B.
P-1, Q-2, R-3
C.
P-3, Q-1, R-2
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 SystemMCQ
A system uses a terminate-and-restart policy for resource allocation. There are 2 processes, P1 and P2, and 1 instance of resource R.
Initially, P1 holds R.
P2 requests R, so P1 is terminated and restarted. P2 now holds R.
P1 requests R, so P2 is terminated and restarted. P1 now holds R.
P2 requests R, so P1 is terminated and restarted. P2 now holds R.
How many distinct processes have been terminated and restarted at least once after this sequence of events?
A.
1
B.
2
C.
3
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: P1 holds R. (0 terminations).
Step 2: P2 requests R. P1 is terminated and restarted. (P1 is now in the terminated count). P2 holds R.
Step 3: P1 requests R. P2 is terminated and restarted. (P2 is now in the terminated count). P1 holds R.
Step 4: P2 requests R. P1 is terminated and restarted. (P1 is terminated again, but already counted). P2 holds R.
Step 5: The distinct processes terminated are P1 and P2. Total = 2.
Answer: 2, which matches option B.
Question 7 · Operating SystemMCQ
A system has two resource types, R1 and R2, with 1 instance each. Process PA holds R1. Process PB holds R2.
PA requests R2. The system uses a terminate-and-restart policy: the requester terminates the holder, takes the resource, and restarts the holder.
After PA's request is resolved, PB immediately requests R1.
What is the net change in the total number of resources held by PA from the initial state to the final state?
A.
-2
B.
1
C.
-1
D.
0
Correct Answer:
C
Step-by-Step Solution
Key idea: Trace the resource holdings of PA step-by-step and calculate Final - Initial.
Step 1: Initial state: PA holds R1. Total resources held by PA = 1.
Step 2: PA requests R2. PA terminates PB, takes R2, and restarts PB. PA now holds R1 and R2. Total = 2.
Step 3: PB requests R1. PB terminates PA, takes R1, and restarts PA. PA is restarted and holds 0 resources. Total = 0.
Step 4: Net change for PA = Final (0) - Initial (1) = -1.
Answer: -1, which matches option C.
Question 8 · Operating SystemMCQ
To guarantee that a deadlock is IMPOSSIBLE in a system with N processes and a single resource type, what is the minimum number of Coffman conditions that the operating system must strictly negate?
A.
1
B.
2
C.
3
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 SystemNAT
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: N×(M−1)+1.
Step 1: Identify the number of processes N=3 and the maximum resources needed per process M=4.
Step 2: Calculate the worst-case scenario where every process holds exactly M−1 resources without being able to finish. Total tied up = 3×(4−1)=3×3=9.
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 = 9+1=10.
Answer: 10.00
Question 10 · Operating SystemMSQ
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?
A.
The minimum total number of resource instances required to guarantee the system is completely deadlock-free is 10.
B.
If the system has 9 resource instances, it is guaranteed to be deadlock-free.
C.
If the system has 12 resource instances, it is guaranteed to be deadlock-free.
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: N×(M−1)+1.
Step 1: Identify N=3 processes and M=4 maximum resources per process.
Step 2: Calculate the worst-case tie-up: every process holds M−1=3 resources. Total tied up = 3×3=9. This makes option D true.
Step 3: Calculate the minimum resources to guarantee deadlock freedom: Worst-case tie-up + 1 = 9+1=10. 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 (3×4=12), so it is guaranteed to be deadlock-free. Option C is true.