Why Shared State Breaks
Two threads, one field, and the two different ways it goes wrong.
Two threads incrementing the same counter a thousand times each do not produce two thousand, and the reason is not what most people guess. There are two separate failures hiding in that sentence — one about interleaving and one about what a thread can see — and telling them apart is the whole topic. volatile fixes exactly one of them.
Contents
9 cardsnot started