Process Synchronization: GATE CS Previous Year Questions

Process Synchronization · Operating System

41 questions · asked in 23 of 27 years (2000–2026)

MCQ 34 · MSQ 4 · NAT 31-mark 22 · 2-mark 19

2000Questions per year2026

Questions 1–5 of 41

Q1GATE 2026 (Session 2)2 marksMSQ
Consider three processes P1, P2\text{P1, P2}, and P3\text{P3} running identical code, as shown in the pseudocode below. A\text{A} and B\text{B} are two binary semaphores initialized to 11 and 00, respectively. X\text{X} is a shared variable initialized to 00. Each line in the pseudocode is executed atomically.

Pseudocode of P1, P2, and P3

  Wait(A);
  Print(*);
  X = X+1;
  If (X == 2)
  	{
  		Print($);
  		Signal(B);
  	}
  Signal(A);
  Wait(B);
  Print(#);
  Signal(B); 
Assume that any of the three processes can start to execute first and context switching can happen between these processes at any arbitrary time and in any arbitrary order.

Which of the following patterns is/are possible to be generated as an outcome of the execution of these three processes?

One or more options are correct.

Q2GATE 2024 (Session 1)2 marksMCQ−0.67 if wrong
Consider the following two threads T1\mathrm{T} 1 and T2\mathrm{T} 2 that update two shared variables a\mathrm{a} and b\mathrm{b}. Assume that initially a=b=1\mathrm{a}=\mathrm{b}=1. Though context switching between threads can happen at any time, each statement of T1\mathrm{T} 1 or T2\mathrm{T} 2 is executed atomically without interruption.

T1 T2a=a+1;b=2∗b;b=b+1;a=2∗a;\begin{array}{cc} \mathrm{T} 1 & \mathrm{~T} 2 \\ \mathrm{a}=\mathrm{a}+1 ; & \mathrm{b}=2*\mathrm{b} ; \\ \mathrm{b}=\mathrm{b}+1 ; & \mathrm{a}=2*\mathrm{a} ; \end{array}

Which one of the following options lists all the possible combinations of values of a\mathrm{a} and b\mathrm{b} after both T1\mathrm{T} 1 and T2\mathrm{T} 2 finish execution?

Q3GATE 2024 (Session 2)2 marksMSQ
Consider a multi-threaded program with two threads T1 and T2. The threads share two semaphores: s1 (initialized to 1) and s2 (initialized to 0). The threads also share a global variable x (initialized to 0). The threads execute the code shown below.

// code of T1
wait(s1);
x = x+1;
print(x);
wait(s2);
signal(s1);

// code of T2
wait(s1);
x = x+1;
print(x);
signal(s2);
signal(s1);
Which of the following outcomes is/are possible when threads T1 and T2 execute concurrently?

One or more options are correct.

Q4GATE 20232 marksMCQ−0.67 if wrong
Consider the two functions incr and decr shown below.

incr(){
  wait(s);
  X = X+1;
  signal(s);
}

decr(){
  wait(s);
  X = X-1;
  signal(s);
}

There are 5 threads each invoking incr once, and 3 threads each invoking decr once, on the same shared variable X. The initial value of X is 10.
Suppose there are two implementations of the semaphore ss, as follows:

I-1: s is a binary semaphore initialized to 1.
I-2: s is a counting semaphore initialized to 2.

Let V1, V2 be the values of X at the end of execution of all the threads with implementations I-1, I-2, respectively.
Which one of the following choices corresponds to the minimum possible values of V1, V2, respectively?

Q5GATE 20221 markMCQ−0.33 if wrong
Consider the following threads, T1,T2, and T3T_1, T_2, \text{ and }T_3 executing on a single processor, synchronized using three binary semaphore variables, S1,S2, and S3S_1, S_2, \text{ and }S_3, operated upon using standard wait()wait() and signal()signal(). The threads can be context switched in any order and at any time.
T1T2T3
while(true){
  wait(S3);
  print(“C”);
  signal(S2); }
while(true){
  wait(S1);
  print(“B”);
  signal(S3); }
while(true){
  wait(S2);
  print(“A”);
  signal(S1); }

Which initialization of the semaphores would print the sequence BCABCABCA ...?

Keep practising

Topics in Operating System

All CS topics ›