CS FundamentalsVery hardGATE CS
Shared x = 0, mutex m = 1. T1: wait(m); x = x + 1; signal(m). T2: wait(m); x = x + 2; signal(m). T3: x = x + 4 (no lock). Each assignment is load, add, store. What is the set of possible final values?
- A. {3, 4, 5, 6, 7}
- B. {7}
- C. {3, 7}
- D. {1, 2, 3, 4, 5, 6, 7}
Correct answer: A. {3, 4, 5, 6, 7}
T1 and T2 are serialised with each other but T3 is not, so T3 can overwrite their work or be overwritten by either of them. Possible values: {3, 4, 5, 6, 7}. A lock that only some threads use protects nothing against the others.
More Operating Systems questions
- A counting semaphore is implemented WITHOUT busy waiting: wait() decrements the value and, if it becomes negative, puts the caller on the…
- Strict alternation uses a shared turn variable: P0: while (turn != 0); CS; turn = 1; P1: while (turn != 1); CS; turn = 0;. P0 wants to…
- Two processes each run flag[i] = true; while (flag[j]); CS; flag[i] = false; (no turn variable). Which statement is correct?
- Two processes each run while (flag[j]); flag[i] = true; CS; flag[i] = false; (check first, then set). Which property fails?
- Peterson's algorithm is written with turn = i; (giving the turn to ITSELF) instead of turn = j;: flag[i] = true; turn = i; while (flag[j]…
- stdout is a pipe (fully buffered) and every fork() succeeds. What is the complete output, up to the order of the lines? c int main() {…