Thursday, September 23, 2010

Atomic Variables

  • Better volatile vriables
  • same memory semantics as volatile
  • support of atomic updates
  • Compare and Swap - atomic read modify write instruction. supported by Atomic variable classes.
  • CAS is an  optimistic technique.
  • With CAS under a contention scenario only one thread wins and updates the variable's value & the rest loose. Loosers are not punished by suspension, as they could be if they fail to acquire a lock.
  • Looser threads are not blocked and they can decide whether they want to retry or do nothing.