GATE GUIDE

Process Synchronization Questions in GATE CSE: Method and Traps

By MD ANISH AHAMADUpdated 26 Oct 20269 min read
Process Synchronization Questions in GATE CSE: Method and Traps

A synchronization question prints ten to fifteen lines of concurrent code and asks which properties hold. You cannot answer it by reading the code the way you read a program that runs once. The answer lives in an interleaving the listing does not show, and the setter picked that listing because one specific interleaving breaks something. The whole skill is finding that interleaving quickly.

In this guide
  1. Key takeaways
  2. Where synchronization sits in the paper
  3. A counter is three instructions, not one
  4. The three requirements, checked separately
  5. Semaphores and what a negative value means
  6. Producer-consumer: which ordering kills it
  7. Readers-writers and who starves
  8. The procedure to run in the exam
  9. How to practise

Key takeaways

Where synchronization sits in the paper

The official 2027 syllabus text for Section 8 reads: system calls, processes, threads, inter-process communication, concurrency and synchronization, deadlock, CPU and I/O scheduling, memory management and virtual memory, file systems. Concurrency and synchronization is named directly, and it is unchanged from 2026.

Third-party analyst compilations place Operating Systems between 6 and 16 marks per paper across 2009 to 2026, with an average near 8.8. The 2009 figure of 16 comes from a 100-mark paper with no General Aptitude section, so it is not a trend. Splitting the series, 2009 to 2017 averages about 9.3 and 2018 to 2026 about 8.3, a mild decline. One analyst counted five Operating Systems questions in the 2026 shift-2 paper. These numbers are unofficial, and sources disagree by two or three marks because borderline questions get classified differently.

Inside the subject, the code-property question is one of the most reliable items there is: some form of it appears in essentially every paper. The full subject ranking sits in the Operating Systems important topics guide. The number of questions of each type and the marking scheme are fixed by the official notification, so check the current one rather than an old coaching PDF.

A counter is three instructions, not one

Write the increment the way the machine sees it:

LOAD  R, x
ADD   R, 1
STORE x, R

Between any two of those lines the scheduler can switch. That is the entire mechanism behind every "possible final values" question.

Take nn processes, each executing that increment kk times, with xx starting at 00.

The maximum is nknk. Run the processes one after another with no overlap and every increment sees the previous one.

The minimum is 2 whenever k≥2k \ge 2 and n≥2n \ge 2, not 1. Here is the argument, and it is worth memorising because the trap is the off-by-one. A store always writes a register value of at least 1, so from the first store onwards xx can never be 0 again. For the final value to be 1, the process that performs the last store must have read 0 during its own final increment. Reading 0 means no store had happened yet anywhere, including that process's own earlier increments, which contradicts k≥2k \ge 2. So 1 is unreachable and 2 is the floor.

Construct it for n=2n = 2, k=2k = 2 to see the shape: both processes load 0, the first finishes both of its increments while the second sits on a stale register, then the second stores 1 over everything, reloads, and the pair finish at 2. If each process increments exactly once, the minimum is 1 instead, because there are no earlier stores to contradict. Read the value of kk before answering.

The three requirements, checked separately

A correct solution must satisfy all three. Most flawed textbook attempts satisfy two, and the question asks which one is missing.

Attempt Mutual exclusion Progress Bounded waiting
Strict alternation, one shared turn variable Yes No Yes
Each process sets its own flag, then waits for the other's flag Yes No, both can deadlock No
Each process checks the other's flag, then sets its own No Yes Yes
Peterson's solution, flag array plus turn Yes Yes Yes
Spin lock from test-and-set, no waiting array Yes Yes No

Two distinctions carry marks. First, progress is not the same as deadlock-freedom: strict alternation never deadlocks, yet it fails progress because an uninterested process holding the turn locks the other one out. Second, a test-and-set lock is perfectly safe but unfair, and a process can be overtaken any number of times, which is exactly where bounded waiting dies. Peterson's variants are built by moving one line, usually the flag assignment past the turn assignment, and the answer changes to "mutual exclusion fails".

Semaphores and what a negative value means

A binary semaphore takes only 0 and 1 and is used as a lock. A counting semaphore starts at any non-negative integer and represents available units of a resource.

Under the usual definition, wait decrements first and blocks the caller if the value has gone negative; signal increments and wakes one blocked process if the value is still at most 0. Two consequences get examined directly:

Some books clamp the value at 0 and keep the queue separately. The two conventions give different numeric answers, so read the question's definition before computing anything. Ordering questions exploit the same machinery: a semaphore initialised to 0 is a one-shot permission slip that forces statement B to run after statement A.

Producer-consumer: which ordering kills it

The standard bounded buffer of size NN uses empty = N, full = 0, mutex = 1. The producer's entry looks like this:

wait(empty); wait(mutex);
  deposit item
signal(mutex); signal(full);

Swap the first two lines and the solution deadlocks. A producer takes the mutex, finds the buffer full, blocks on empty while still holding the mutex, and no consumer can get in to free a slot. The mirror bug on the consumer side deadlocks on an empty buffer. The rule is one line long: acquire the counting semaphore first, the mutex second. Reversing the two signals only delays a wakeup and is harmless, which is the option most candidates tick by mistake.

Readers-writers and who starves

In the readers-preference solution, readcount is guarded by its own mutex, the first reader performs wait on the writer semaphore and the last reader signals it. Mutual exclusion between a writer and everyone else holds, but a steady stream of readers keeps the writer semaphore permanently held and the writer starves. The writers-preference variant flips the problem and readers starve. Only the third variant, which forces everyone through a queue semaphore, is starvation-free. Questions ask which of the three suffers which starvation, and whether removing the mutex around readcount breaks correctness. It does: the increment is non-atomic, so two readers can both think they are first or both think they are last.

The procedure to run in the exam

  1. List the shared state and its initial values: semaphores, flags, turn, counters. Write them at the top of your rough sheet.
  2. Mark what is atomic. Each wait and signal is atomic. Every plain assignment, comparison and increment is not.
  3. Build the worst case, not the average case. Freeze each process just before a store or just after a load, then resume them in the order that does the most damage. An average interleaving proves nothing.
  4. Check the three requirements in order, and check each against its own definition rather than your memory of a similar problem.
  5. Ask what happens at the boundaries: buffer exactly full, buffer exactly empty, both processes requesting at the same instant, one process never leaving its remainder section.

These items are increasingly set as multiple-select. There is no partial credit, so every option has to be decided on its own evidence. Tick an option only when you can name the interleaving that proves it or the argument that rules it out; a guessed tick loses the whole question rather than part of it. That discipline is covered further in the guide to MSQ, NAT and MCQ strategy.

How to practise

Build one page of skeletons: strict alternation, the two flag variants, Peterson's, a test-and-set lock, the bounded buffer, and readers-preference. For each one, write the single interleaving that breaks it, in load and store steps, not in prose. Once those six are in your hand you will recognise almost any printed listing as a mutation of one of them, and the mutation is the answer.

Then rehearse the counter argument with different values of nn and kk until the minimum of 2 stops feeling surprising. The error list that this topic shares with the rest of the paper is in common mistakes that cost marks, and the evidence-based view of which topics repay this level of drilling is in the guide to important questions for 2027. The Operating Systems chapter of the GATE CSE 2027 book carries a worked bank of synchronization items with full interleaving traces and a year-by-year map of which property was tested in which paper.

Frequently asked questions

What are the three requirements of a correct critical-section solution?

Mutual exclusion, progress and bounded waiting. Mutual exclusion means at most one process is inside the critical section at any instant. Progress means the decision about who enters next cannot be postponed indefinitely by processes that are sitting in their remainder section. Bounded waiting means there is a limit on how many times other processes can enter after a process has requested entry.

Why is the minimum final value of a shared counter 2 and not 1?

A store writes a register value of at least one, so the variable can never return to zero once any process has stored. For a final value of one, the last writer must have read zero during its final increment, which is impossible if that process already completed an earlier increment of its own. So two is the floor when each process increments at least twice.

What does a negative semaphore value mean?

Under the standard definition where wait decrements first and blocks when the value becomes negative, the absolute value of a negative semaphore equals the number of processes blocked on it. A value of −3-3 means three processes are waiting. Some textbooks never let the value fall below zero, so the question has to state which definition it is using.

Why does swapping wait(mutex) and wait(empty) cause deadlock in producer-consumer?

A producer that acquires the mutex before checking for a free slot can find the buffer full while still holding the mutex. It blocks on the empty semaphore and never releases the mutex, so no consumer can get in to free a slot. The two waits must be ordered counting semaphore first, mutex second. The two signals can be in either order.

Does strict alternation satisfy mutual exclusion?

Yes. A single shared turn variable guarantees mutual exclusion and also bounded waiting, since a process waits at most one turn. What it fails is progress. If the process whose turn it is has finished and gone back to its remainder section, the other process cannot enter even though the critical section is completely free.

How many marks is Operating Systems worth in GATE CSE?

Analyst compilations put Operating Systems at roughly 6 to 16 marks per paper between 2009 and 2026, averaging close to 9, with a tight band of 6 to 10 since 2018. These counts are unofficial and analysts classify borderline questions differently. Synchronization is one of the few subtopics that shows up in almost every paper.

Sources

Dates, fees and the syllabus are set by the GATE 2027 organising institute and can change. Always confirm at gate2027.iitm.ac.in.

Keep reading

GATE CSE 2027 book1,020 pages · ₹250 ₹300
Buy now — ₹250