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 31–35 of 41

Q31GATE 20061 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?

Q32GATE 20061 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?

Q33GATE 20061 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?

Q34GATE 20051 markMCQ−0.33 if wrong
Two concurrent processes P1 and P2 use four shared resources R1, R2, R3 and R4, as shown below.
P1P2Compute: Compute;Use R1; Use R1;Use R2; Use R2;Use R3; Use R3;Use R4; Use R4;\begin{array}{|l|l|}\hline \textbf{P1} & \textbf{P2} \\ \text{Compute: } & \text{Compute;} \\ \text{Use $R1;$ } & \text{Use $R1;$} \\ \text{Use $R2;$ } & \text{Use $R2;$}\\ \text{Use $R3;$ } & \text{Use $R3;$} \\ \text{Use $R4;$ } & \text{Use $R4;$} \\\hline \end{array}
Both processes are started at the same time, and each resource can be accessed by only one process at a time The following scheduling constraints exist between the access of resources by the processes:
P2 must complete use of R1 before P1 gets access to R1.
P1 must complete use of R2 before P2 gets access to R2.
P2 must complete use of R3 before P1 gets access to R3.
P1 must complete use of R4 before P2 gets access to R4.
There are no other scheduling constraints between the processes. If only binary semaphores are used to enforce the above scheduling constraints, what is the minimum number of binary semaphores needed?

Q35GATE 20051 markMCQ−0.33 if wrong
Given below is a program which when executed spawns two concurrent processes :
semaphore X : = 0 ;
/* Process now forks into concurrent processes P1 & P2 */
P1P2repeat forever repeat foreverV(X); P(X);Compute; Compute;P(X); V(X);\begin{array}{|l|l|}\hline \text{$P1$} & \text{$P2$} \\\hline \text{repeat forever } & \text{repeat forever} \\ \text{$V (X) ;$ } & \text{$ P(X) ;$} \\ \text{Compute; } & \text{Compute;}\\ \text{$P(X) ;$ } & \text{$V(X) ;$} \\\hline \end{array}
Consider the following statements about processes P1 and P2:
I.It is possible for process P1 to starve.
II.It is possible for process P2 to starve.
Which of the following holds?

Keep practising

Topics in Operating System

All CS topics ›