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 26–30 of 41

Q26GATE 20071 markMCQ−0.33 if wrong
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
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

Q27GATE 20071 markMCQ−0.33 if wrong
Processes P1 and P2 use critical_flag in the following routine to achieve mutual exclusion. Assume that critical_flag is initialized to FALSE in the main program.
 get_exclusive_access ( )
{
    if (critical _flag == FALSE) {
        critical_flag = TRUE ;
        critical_region () ;
        critical_flag = FALSE;
    }
}

Consider the following statements.

i.It is possible for both P1 and P2 to access critical_region concurrently.
ii.This may lead to a deadlock.

Which of the following holds?

Q28GATE 20071 markMCQ−0.33 if wrong
Two processes, P1 and P2, need to access a critical section of code. Consider the following synchronization construct used by the processes:
/* P1 */                        /* P2 */
while (true) {                  while (true) {
   wants1 = true;                  wants2 = true;
   while (wants2==true);           while (wants1==true);
   /* Critical                     /* Critical
      Section */                      Section */
   wants1=false;                   wants2=false;
}                               }
/* Remainder section */         /* Remainder section */

Here, wants1 and wants2 are shared variables, which are initialized to false. Which one of the following statements is TRUE about the above construct?

Q29GATE 20061 markMCQ−0.33 if wrong
The wait and signal operations of a monitor are implemented using semaphores as follows. In the following,
x is a condition variable,
mutex is a semaphore initialized to 1,
x_sem is a semaphore initialized to 0,
x_count is the number of processes waiting on semaphore x_sem, initially 0,
next is a semaphore initialized to 0,
next_count is the number of processes waiting on semaphore next, initially 0.
The body of each procedure that is visible outside the monitor is replaced with the following:
 P(mutex);
...
body of procedure
...
if (next_count > 0)
    V(next);
else
    V(mutex);

Each occurrence of x.wait is replaced with the following:
 x_count = x_count + 1;
if (next_count > 0)
    V(next);
else
    V(mutex);
------------------------------------------------------------ E1;
x_count = x_count - 1;

Each occurrence of x.signal is replaced with the following:
if (x_count > 0)
{
    next_count = next_count + 1;
    ------------------- E2;
    P(next);
    next_count = next_count - 1;
} 

For correct implementation of the monitor, statements E1 and E2 are, respectively,

Q30GATE 20061 markMCQ−0.33 if wrong
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.
Producer ProcessConsumer ProcessProduce an item;Wait(E);Wait(F);Wait(S);Wait(S);Remove an item from the buffer;Append the item to the buffer;Signal(S);Signal(S);Signal(F);Signal(E);Consume the item;\begin{array}{|l|l|}\hline \textbf{Producer Process} & \textbf{Consumer Process} \\\hline \text{Produce an item;} & \text{Wait(E);} \\ \text{Wait(F);} & \text{Wait(S);} \\ \text{Wait(S);} & \text{Remove an item from the buffer;} \\\text{Append the item to the buffer;} & \text{Signal(S);} \\ \text{Signal(S);} & \text{Signal(F);} \\ \text{Signal(E);} & \text{Consume the item;} \\\hline \end{array}

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

Keep practising

Topics in Operating System

All CS topics ›