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?

  1. A. {3, 4, 5, 6, 7}
  2. B. {7}
  3. C. {3, 7}
  4. 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

Exams that ask this topic