Module 7: Synchronization
  Lecture 14: Scalable Locks and Barriers
 


Ticket Lock

  • Similar to Bakery algorithm but simpler
  • A nice application of fetch & inc
  • Basic idea is to come and hold a unique ticket and wait until your turn comes
    • Bakery algorithm failed to offer this uniqueness thereby increasing complexity

    Shared: ticket = 0, release_count = 0;
    Lock: fetch & inc reg1, ticket_addr
    Wait: lw reg2, release_count_addr /* while ( release_count != ticket); */
    sub reg3, reg2, reg1
    bnez reg3, Wait

    Unlock: addi reg2, reg2, 0x1 /* release_count ++ */
    sw reg2, release_count_addr

  • Initial fetch & inc generates O(P) traffic on bus-based machines (may be worse in DSM depending on implementation of fetch & inc)
  • But the waiting algorithm still suffers from 0.5P 2 messages asymptotically
    • Researchers have proposed proportional backoff i.e. in the wait loop put a delay proportional to the difference between ticket value and last read release_count
  • Latency and storage-wise better than Bakery
  • Traffic-wise better than TTS and Bakery (I leave it to you to analyze the traffic of Bakery)
  • Guaranteed fairness: the ticket value induces a FIFO queue