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 16–20 of 41

Q16GATE 2014 (Session 2)2 marksMCQ−0.67 if wrong
Consider the procedure below for the Producer-Consumer problem which uses semaphores:
semaphore n = 0;
semaphore s = 1;
void producer()                    void consumer()
{                                  {
      while(true)                        while(true)
      {                                  {
       produce();                         semWait(s);
       semWait(s);                        semWait(n);
       addToBuffer();                     removeFromBuffer();
       semSignal(s);                      semSignal(s);
       semSignal(n);                      consume();
      }                                  }
}                                  }

Which one of the following is TRUE?

Q17GATE 20132 marksMCQ−0.67 if wrong
A certain computation generates two arrays a and b such that a[i]=f(i)for o≤i<no\leq i \lt n and b[i] = g (a[i] )for o≤i<no\leq i \lt n. Suppose this computation is decomposed into two concurrent processes X and Y such that X computes the array a and Y computes the array b. The processes employ two binary semaphores R and S, both initialized to zero. The array a is shared by the two processes. The structures of the processes are shown below.
Process X;                    Process Y;
private i;                    private i;
for (i = 0; i < n; i ++) {    for (i = 0; i < n; i ++) {
   a[i] = f(i);                  EntryY(R, S);
   ExitX(R, S);                  b[i] = g(a[i]);
}                             }

Which one of the following represents the CORRECT implementations of ExitX and EntryY?

Q18GATE 20132 marksMCQ−0.67 if wrong
A shared variable x, initialized to zero, is operated on by four concurrent processes W, X, Y, Z as follows. Each of the processes W and X reads x from memory, increments by one, stores it to memory, and then terminates. Each of the processes Y and Z reads x from memory, decrements by two, stores it to memory, and then terminates. Each process before reading x invokes the P operation (i.e., wait) on a counting semaphore S and invokes the V operation (i.e., signal) on the semaphore S after storing x to memory. Semaphore S is initialized to two. What is the maximum possible value of x after all processes complete execution?

Q19GATE 20131 markMCQ−0.33 if wrong
Three concurrent processes X, Y, and Z execute three different code segments that access and update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes the P operation on semaphores c, d, and a before entering the respective code segments. After completing the execution of its code segment, each process invokes the V operation (i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one. Which one of the following represents a deadlock-free order of invoking the P operations by the processes?

Q20GATE 20122 marksMCQ−0.67 if wrong
Fetch_And_Add(X,i) is an atomic Read-Modify-Write instruction that reads the value of memory location X, increments it by the value i, and returns the old value of X. It is used in the pseudocode shown below to implement a busy-wait lock. L is an unsigned integer shared variable initialized to 0. The value of 0 corresponds to lock being available, while any non-zero value corresponds to the lock being not available.
 AcquireLock(L){
   while (Fetch_And_Add(L,1))
        L = 1;
}
ReleaseLock(L){
     L = 0;
} 
This implementation

Keep practising

Topics in Operating System

All CS topics ›