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 36–40 of 41

Q36GATE 20041 markMCQ−0.33 if wrong
The semaphore variables full, empty and mutex are initialized to 0, n and 1, respectively. Process P1 repeatedly adds one item at a time to a buffer of size n, and process P2 repeatedly removes one item at a time from the same buffer using the programs given below. In the programs, K, L, M and N are unspecified statements.
P1
 while (1) {
    K;
    P(mutex);
    Add an item to the buffer;
    V(mutex);
    L;
}

P2
while (1) {
    M;
    P(mutex);
    Remove an item from the buffer;
    V(mutex);
    N;
} 

The statements K, L, M and N are respectively

Q37GATE 20041 markMCQ−0.33 if wrong
Consider two processes P1 and P2 accessing the shared variables X and Y protected by two binary semaphores Sx and Sy respectively, both initialized to 1. P and V denote the usual semaphore operators, where P decrements the semaphore value, and V increments the semaphore value. The pseudo-code of P1 and P2 is as follows:
P1
 While true do {
   L1 : ................
   L2 : ................
   X = X + 1;
   Y = Y - 1;
   V(Sx);
   V(Sy);             
 }

P2
 While true do {
   L3 : ................   
   L4 : ................
   Y = Y + 1;
   X = Y - 1;
   V(Sy);
   V(Sx);            
}
In order to avoid deadlock, the correct operators at L1 , L2 , L3 and L4 are respectively.

Q38GATE 20031 markMCQ−0.33 if wrong
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
 Process P:
while (1) {
W:
   print '0';
   print '0';
X:
}
 
Process Q:
while (1) {
Y:
   print '1';
   print '1';
Z:
}
Synchronization statements can be inserted only at points W, X, Y and Z.
Which of the following will ensure that the output string never contains a substring of the form 01n001^{n}0 or 10n110^{n}1, where n is odd?

Q39GATE 20031 markMCQ−0.33 if wrong
Suppose we want to synchronize two concurrent processes P and Q using binary semaphores S and T. The code for the processes P and Q is shown below.
 Process P:
while (1) {
W:
   print '0';
   print '0';
X:
}
 
Process Q:
while (1) {
Y:
   print '1';
   print '1';
Z:
}
Synchronization statements can be inserted only at points W, X, Y and Z.

Which of the following will always lead to an output staring with '001100110011' ?

Q40GATE 20011 markMCQ−0.33 if wrong
Consider Peterson's algorithm for mutual exclusion between two concurrent processes i and j . The program executed by process is shown below.
 repeat   
      flag [i] = true; 
      turn = j; 
      while ( P ) do no-op; 
      Enter critical section, perform actions, then exit critical 
      section 
      flag [ i ] = false; 
      Perform other non-critical section actions. 
   until false; 
For the program to guarantee mutual exclusion, the predicate P in the while loop should be

Keep practising

Topics in Operating System

All CS topics ›