CS FundamentalsVery hardGATE CS

In Lamport's bakery algorithm, why does a process pick a number with `number[i] = max(number) + 1` while choosing[i] is true, and break ties by process ID?

  1. A. Because max() is atomic in hardware
  2. B. Because numbers are always distinct, the ID is only for logging
  3. C. Two processes can read the same max concurrently and get equal numbers, so ties must be broken by ID, and choosing[] prevents comparing against a half-written number
  4. D. Because choosing[] implements a spinlock around max()

Correct answer: C. Two processes can read the same max concurrently and get equal numbers, so ties must be broken by ID, and choosing[] prevents comparing against a half-written number

Taking a ticket is not atomic, so equal tickets are possible; ordering by (number, id) makes the order total. The choosing flag makes others wait until a process's ticket is fully written before comparing.

More Operating Systems questions

Exams that ask this topic