Why Shared State Breaks
Why shared state breaks between threads: race conditions, non-atomic operations, visibility, and choosing volatile, atomics or locks.
What goes wrong when two threads use the same data. Two threads incrementing one counter a thousand times each do not reliably produce two thousand, and the reason is two separate failures: one about operations interleaving, and one about what a thread can see of another's writes. It covers race conditions, why count++ is not atomic, two examples of lost updates, visibility and volatile, and choosing between volatile, atomic classes and locks. It leaves out the formal Java Memory Model.
Contents
9 cardsnot started