GATE 2006 Computer Science and Information Technology (CS) Questions with Solutions

GATE 2006

191 questions

MCQ 1911-mark 191

Questions 146–150 of 191

Q146Process Synchronization1 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

Q147Process Synchronization1 markMCQ−0.33 if wrong
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.
 void barrier (void) {
1:   P(S);
2:   process_arrived++;
3.   V(S);
4:   while (process_arrived !=3);
5:   P(S);
6:   process_left++;
7:   if (process_left==3) {
8:      process_arrived = 0;
9:      process_left = 0;
10:  }
11:  V(S);
}
The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally.

Which one of the following rectifies the problem in the implementation?

Q148Process Synchronization1 markMCQ−0.33 if wrong
Barrier is a synchronization construct where a set of processes synchronizes globally i.e. each process in the set arrives at the barrier and waits for all others to arrive and then all processes leave the barrier. Let the number of processes in the set be three and S be a binary semaphore with the usual P and V functions. Consider the following C implementation of a barrier with line numbers shown on left.
 void barrier (void) {
1:   P(S);
2:   process_arrived++;
3.   V(S);
4:   while (process_arrived !=3);
5:   P(S);
6:   process_left++;
7:   if (process_left==3) {
8:      process_arrived = 0;
9:      process_left = 0;
10:  }
11:  V(S);
}
The variables process_arrived and process_left are shared among all processes and are initialized to zero. In a concurrent program all the three processes call the barrier function when they need to synchronize globally.

The above implementation of barrier is incorrect. Which one of the following is true?

Q149Process Synchronization1 markMCQ−0.33 if wrong
The atomic feth-and-set x,y instruction unconditionally sets the memory location x to 1 and fetches the old value of x in y without allowing any intervening access to the memory location x . Consider the following implementation of P and V functions on a binary semaphore S.
void P(binary_semaphore*S){
   unsigned y;
   unsigned*x =& (S->value);
   do {
          fetch-and-set x,y;
         } while(y);
 }
void V (binary_semphore*S){
      S_>value = 0;
}
Which one of the following is true?

Q150Deadlock1 markMCQ−0.33 if wrong
Consider the following snapshot of a system running n processes. Process i is holding xix_{i} instances of a resource R, for 1≤i≤n1\leq i\leq n. Currently, all instances of R are occupied. Further, for all i , process i has placed a request for an additional yiy_{i}, instances while holding the xix_{i} instances it already has, There are exactly two processes p and q such that ypy_{p}=yqy_{q}=0. Which one of the following can serve as a necessary condition to guarantee that the system is not approaching a deadlock?