Classical Synchronization Problems MCQs: 12 Solved Questions with Explanations

Test your grasp of bounded buffers, readers-writers and dining philosophers through 12 solved MCQs. Trace each state change before reading the explanation.

KnowledgeGate Team

Exam prep & CS education

Updated 14 Sep 20268 min read

Semaphore values, wait order and circular-wait conditions make familiar producer-consumer, readers-writers and dining-philosophers questions deceptively hard. The questions test recognition, code tracing and deadlock reasoning. Choose an option, note one invariant or state change, then read the explanation. KnowledgeGate offers over 20 questions for practice on classical synchronization problems; its GATE CS Exam Preparation page places the topic in the wider syllabus.

Classical synchronization problems in one state model

Bounded buffer coordinates free and filled slots. Readers-writers allows concurrent readers but gives writers exclusive access. Dining philosophers exposes circular wait when each philosopher holds one fork and waits for the next.

Initialize a bounded buffer of capacity N = 3 with empty = 3, full = 0 and mutex = 1.

  • P1 runs wait(empty), making empty = 2, then wait(mutex), making mutex = 0. After inserting A, it signals mutex and full. The state satisfies empty + full = 2 + 1 = 3.

  • P2 repeats for B, ending with empty = 1, full = 2 and mutex = 1. Again, 1 + 2 = 3.

  • C1 runs wait(full), making full = 1, locks mutex, removes A, unlocks, then signals empty to 2. The state gives 2 + 1 = 3.

Counts stay between 0 and 3. Check availability before entry, protect shared updates with the mutex, and never block on availability while holding that mutex. See Semaphore Trace Tables for GATE: 3 Classic Problems for longer traces.

Classical problems MCQs 1-3: names and synchronization tools

Question 1

The Bounded buffer problem is also known as __________.

  • (a) Producer - consumer problem

  • (b) Reader - writer problem

  • (c) Dining Philosophers problem

  • (d) Both (b) and (c)

Answer: (a)

The producer adds items to a finite buffer; the consumer removes them. Bounded buffer and producer-consumer name the same problem. The other options model different constraints.

Question 2

In a producer-consumer scenario also known as Bounded-Buffer Problem, what would be the most appropriate synchronization primitive to ensure that the consumer waits when the buffer is empty?

  • (a) Spinlock

  • (b) Mutex lock

  • (c) Semaphore

  • (d) Monitors

Answer: (c)

full counts available items. At zero, wait(full) blocks the consumer until a producer inserts and signals. A mutex protects access but cannot count items.

Question 3

Producer–consumer problem can be solved using:

  • (a) Semaphores

  • (b) event counters

  • (c) Monitors

  • (d) All of the above

Answer: (d)

Semaphores coordinate counts, event counters expose state changes, and monitors provide condition-based waiting. Each can express producer-consumer coordination.

Classical problems MCQs 4-6: readers-writers invariants

Question 4

To overcome difficulties in Readers-Writers problem, which of the following statement/s is/are true?

(i) Writers are given exclusive access to shared objects.

(ii) Readers are given exclusive access to shared objects.

(iii) Both Readers and Writers are given exclusive access to shared objects.

Choose the correct answer from the code given below :

Code:

  • (a) (i) only

  • (b) (ii) only

  • (c) (iii) only

  • (d) Both (ii) and (iii)

Answer: (a)

Writers need exclusive access to prevent inconsistent reads or updates. Multiple readers may inspect unchanged data together. Only statement (i) is true.

Question 5

Which of the following statements is/are true about readers-writers synchronisation problem?

(i) If two readers access the shared data simultaneously, it may face problems.

(ii) It cannot be solved using semaphores.

  • (a) Only (i)

  • (b) Only (ii)

  • (c) Both (i) and (ii)

  • (d) Neither (i) nor (ii)

Answer: (d)

Concurrent readers are safe on unchanged data. Semaphores protect readcount and exclude writers while any reader is active. Both statements are false.

Question 6

Synchronization in the classical readers and writers problem can be achieved through use of semaphores. In the following incomplete code for readers-writers problem, two binary semaphores mutex and wrt are used to obtain synchronization

Code
wait (wrt)
writing is performed
signal (wrt)
wait (mutex)  
readcount = readcount + 1
if readcount = 1 then S1
S2
reading is performed
S3
readcount = readcount - 1
if readcount = 0 then S4 
signal (mutex)

The values of S1, S2, S3, S4, (in that order) are

  • (a) signal (mutex), wait (wrt), signal (wrt), wait (mutex)

  • (b) signal (wrt), signal (mutex), wait (mutex), wait (wrt)

  • (c) wait (wrt), signal (mutex), wait (mutex), signal (wrt)

  • (d) signal (mutex), wait (mutex), signal (mutex), wait (mutex)

Answer: (c)

The first reader acquires wrt, then releases mutex. A reader reacquires mutex before decrementing readcount; the last releases wrt. This is option C.

Classical problems MCQs 7-9: buffer counts and handoff

Question 7

The producer and consumer processes share the following variables:

int n

Semaphore M = 1

Semaphore E = n

Semaphore F = 0

The consumer process must execute ____ and ____ before removing an item from buffer.

  • (a) signal(M), signal(F)

  • (b) signal(M), wait(F)

  • (c) signal(F), wait(M)

  • (d) wait(F), wait(M)

Answer: (d)

F = 0 means no filled slot exists. The consumer uses wait(F) for an item, then acquires M before changing the buffer. Therefore D is safe.

Question 8

Processes P1 and P2 have a producer-consumer relationship, communicating by the use of a set of shared buffers.

Code
P1: repeat
    Obtain an empty buffer
    Fill it
    Return a full buffer
    forever
P2: repeat
    Obtain a full buffer
    Empty it
    Return an empty buffer
    forever

Increasing the number of buffers is likely to do which of the following?

I. Increase the rate at which requests are satisfied (throughput)

II. Decrease the likelihood of deadlock

III. Increase the ease of achieving a correct implementation

  • (a) III only

  • (b) II only

  • (c) I only

  • (d) II and III only

Answer: (c)

Extra buffers let producer and consumer run independently longer, improving throughput. Capacity neither fixes bad locking nor simplifies synchronization. Only statement I follows.

Question 9

The following is a code with two threads, producer and consumer, that can run in parallel. Further, S and Q are binary semaphores equipped with the standard P and V operations.

Code
semaphore S = 1, Q = 0; 
integer x;

producer:                   consumer:
while (true) do             while (true) do
    P(S);                       P(Q);
    x = produce ();             consume (x);
    V(Q);                       V(S);
done                        done

Which of the following is TRUE about the program above?

  • (a) The process can deadlock

  • (b) One of the threads can starve

  • (c) Some of the items produced by the producer may be lost

  • (d) Values generated and stored in 'x' by the producer will always be consumed before the producer can generate a new value

Answer: (d)

S permits production, then stays unavailable until the consumer uses x and signals it. This rendezvous forces consumption before the next production, preventing overwrite.

Classical problems MCQs 10-12: deadlock and circular wait

Question 10

Consider the procedure below for the Producer-Consumer problem which uses semaphores:

Code
semaphore n = 0;

semaphore s = 1;

void producer()
{
        while(true)
        {
             produce();
             semWait(s);
             addToBuffer();
             semSignal(s);
             semSignal(n);
        }
}

void consumer()
{
        while(true)
        {
             semWait(s);
             semWait(n);
             removeFromBuffer();
             semSignal(s);
             consume();
        }
}

Which one of the following is TRUE?

  • (a) The producer will be able to add an item to the buffer, but the consumer can never consume it

  • (b) The consumer will remove no more than one item from the buffer.

  • (c) Deadlock occurs if the consumer succeeds in acquiring semaphore s when the buffer is empty.

  • (d) The starting value for the semaphore n must be 1 and not 0 for deadlock-free operation.

Answer: (c)

The consumer locks s, then blocks on empty n. The producer cannot acquire s to insert and signal n, so they deadlock.

Question 11

Consider the solution to the bounded buffer producer/consumer problem by using general semaphores S, F, and E. The semaphore S is the mutual exclusion semaphore initialized to 1. The semaphore F corresponds to the number of free slots in the buffer and is initialized to N. The semaphore E corresponds to the number of elements in the buffer and is initialized to 0.

Which of the following interchange operations may result in a deadlock?

I. Interchanging Wait (F) and Wait (S) in the Producer process

II. Interchanging Signal (S) and Signal (F) in the Consumer process

  • (a) I Only

  • (b) II Only

  • (c) Neither I nor II

  • (d) Both I and II

Answer: (a)

If the producer locks S before waiting on F in a full buffer, the consumer cannot lock S to free a slot. Signals do not block, so II creates no cycle.

Question 12

A solution to the Dining Philosophers Problem which avoids deadlock is:

  • (a) ensure that all philosophers pick up the left fork before the right fork

  • (b) ensure that all philosophers pick up the right fork before the left fork

  • (c) ensure that one particular philosopher picks up the left fork before the right fork, and that all other philosophers pick up the right fork before the left fork

  • (d) None of the above

Answer: (c)

Uniform fork order lets everyone hold one fork and wait cyclically. Reversing one philosopher breaks circular wait, preventing deadlock.

The traps these classical problems MCQs expose

Trap

Questions to revisit

Availability count versus mutex

Q2, Q7 and Q10

Concurrent readers versus exclusive writers

Q4, Q5 and Q6

Capacity versus correctness

Q8 and Q9

Hold-and-wait or circular wait

Q10, Q11 and Q12

Use the same four-step routine on every trace:

  1. Write the initial values.

  2. Record the mutex owner.

  3. Mark processes blocked at a wait.

  4. Ask which runnable process can issue the required signal. If none can, the trace is deadlocked.

Read Process Synchronization and Semaphores for theory. For the critical-section, Peterson and semaphore-ordering questions that come before the classical trio, work through Process Synchronization MCQs: 12 Solved GATE Questions.

Classical synchronization problems: the next practice step

Redo Q6, Q9, Q10, Q11 and Q12 without the answers. They test reader logic, one-slot handoff, blocking while holding a mutex, unsafe operation order and circular wait. For a sequenced Operating System route after critical-section and semaphore fundamentals, use GATE Guidance by Sanchit Sir. Availability semaphores answer “may I proceed?”, the mutex answers “may I touch shared state?”, and deadlock appears when a process waits for availability while blocking the process that could create it.