Module 7: Synchronization
  Lecture 13: Introduction to Atomic Primitives
 


Compare & Swap

addi reg1, r0, 0x0 /* reg1 has 0x0 */
addi reg2, r0, 0x1 /* reg2 has 0x1 */
Lock: compare & swap reg1, reg2, lock_addr
bnez reg2, Lock

Traffic of Test & Set

  • In some machines (e.g., SGI Origin 2000) uncached fetch & op is supported
    • Every such instruction will generate a transaction (may be good or bad depending on the support in memory controller; will discuss later)
  • Let us assume that the lock location is cacheable and is kept coherent
    • Every invocation of test & set must generate a bus transaction; Why? What is the transaction? What are the possible states of the cache line holding lock_addr ?
    • Therefore all lock contenders repeatedly generate bus transactions even if someone is still in the critical section and is holding the lock
  • Can we improve this?
    • Test & set with backoff