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 11–15 of 41
Consider the following proposed solution for the critical section problem. There are n processes: . In the code,function returns an integer not smaller than any of its arguments. For all i, t[i] is initialized to zero.
Code for Pi:
Which one of the following is TRUE about the above solution?
Code for Pi:
do {
c[i]=1; t[i] = pmax(t[0],...,t[n-1])+1; c[i]=0;
for every j ≠ i in {0,...,n-1} {
while (c[j]);
while (t[j] != 0 && t[j]<=t[i]);
}
Critical Section;
t[i]=0;
Remainder Section;
} while (true); Which one of the following is TRUE about the above solution?
Answer: (A)
This is a bakery-style algorithm. A process takes a ticket t[i] while its c[i] is 1, and every other process waits while c[j] is 1. So when Pi compares tickets, the ticket of every other process is final. Pi then enters only when each other process has ticket 0 or a larger ticket. Any process that takes a ticket later reads t[i] in pmax and gets a larger one, so it waits for Pi. Two processes cannot both pass, so mutual exclusion holds.
However, two processes that run pmax at the same time can take the same ticket, because pmax is not atomic. Then each one waits for the other, since the test t[j] t[i] is true in both directions. This is a deadlock, so progress and bounded waiting also fail, and (D) is false.
Answer: (A)
However, two processes that run pmax at the same time can take the same ticket, because pmax is not atomic. Then each one waits for the other, since the test t[j] t[i] is true in both directions. This is a deadlock, so progress and bounded waiting also fail, and (D) is false.
Answer: (A)
Consider the following two-process synchronization solution.
The shared variable turn is initialized to zero.Which one of the following is TRUE?
Process 0 Process 1
--------- ----------
Entry: loop while (turn == 1); Entry: loop while (turn == 0);
(critical section) (critical section)
Exit: turn = 1; Exit: turn = 0;The shared variable turn is initialized to zero.Which one of the following is TRUE?
Answer: (C)
This solution is strict alternation. The two processes have to go in turns.
Mutual exclusion is satisfied. But take the case where process 0 wants to enter a second time and process 1 does not want to enter at all. Then process 0 has to wait, because turn = 1. It is held up by a process that is not even trying to enter. This breaks the progress requirement.
Answer: This solution violates progress requirement
Mutual exclusion is satisfied. But take the case where process 0 wants to enter a second time and process 1 does not want to enter at all. Then process 0 has to wait, because turn = 1. It is held up by a process that is not even trying to enter. This breaks the progress requirement.
Answer: This solution violates progress requirement
Consider a non-negative counting semaphore S. The operation P(S) decrements S, and V(S) increments S. During an execution, 20 P(S) operations and 12V(S) operations are issued in some order. The largest initial value of S for which at least one P(S) operation will remain blocked is ________.
Answer: 7
Let the initial value of S be x. The 12 V operations add at most 12 more units, so at most x + 12 P operations can finish. If at least one of the 20 P operations must stay blocked, we need: .
Answer: 7
Answer: 7
The following two functions P1 and P2 that share a variable B with an initial value of 2 execute concurrently.
The number of distinct values that B can possibly take after the execution is______________.
P1( ) { P2( ) {
C = B - 1; D = 2 * B;
B = 2 * C; B = D - 1;
} } The number of distinct values that B can possibly take after the execution is______________.
Answer: 3
B starts at 2. Let P1 have steps a: C = B - 1 and b: B = 2C. Let P2 have steps c: D = 2B and d: B = D - 1. Here a comes before b and c comes before d. There are 6 orders:
- a b c d: C = 1, B = 2, D = 4, B = 3 3
- a c b d: C = 1, D = 4, B = 2, B = 3 3
- a c d b: C = 1, D = 4, B = 3, B = 2 2
- c a b d: D = 4, C = 1, B = 2, B = 3 3
- c a d b: D = 4, C = 1, B = 3, B = 2 2
- c d a b: D = 4, B = 3, C = 2, B = 4 4
These cover every interleaving. The distinct values are {2, 3, 4}, so the count is 3.
Answer: 3
- a b c d: C = 1, B = 2, D = 4, B = 3 3
- a c b d: C = 1, D = 4, B = 2, B = 3 3
- a c d b: C = 1, D = 4, B = 3, B = 2 2
- c a b d: D = 4, C = 1, B = 2, B = 3 3
- c a d b: D = 4, C = 1, B = 3, B = 2 2
- c d a b: D = 4, B = 3, C = 2, B = 4 4
These cover every interleaving. The distinct values are {2, 3, 4}, so the count is 3.
Answer: 3
Two processes X and Y need to access a critical section. Consider the following synchronization construct used by both the processes
Here, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?
Process X Process Y
/* other code for process X */ /* other code for process Y */
while(true) while(true)
{ {
varP = true; varQ = true;
while(varQ == true) while(varP == true)
{ {
/* Critical Section */ /* Critical Section */
varP = false; varQ = false;
} }
} }
/* other code for process X */ /* other code for process Y */ Here, varP and varQ are shared variables and both are initialized to false. Which one of the following statements is true?
Answer: (A)
Say X sets varP = true and Y sets varQ = true. Then both while conditions are true, so both processes go into the critical section together mutual exclusion is not guaranteed.
No process ever waits for the other one to move on (the critical section sits inside the loop, not after a busy-wait). So there is no deadlock.
Answer: prevents deadlock but fails to guarantee mutual exclusion
No process ever waits for the other one to move on (the critical section sits inside the loop, not after a busy-wait). So there is no deadlock.
Answer: prevents deadlock but fails to guarantee mutual exclusion
Keep practising
Topics in Operating System
System CallProcessThread
Process SynchronizationYou are here
DeadlockCPU SchedulingDisk SchedulingMemory ManagementFile Systems