Problem Statement
Explain what volatile guarantees and when it’s insufficient.
Explanation
volatile guarantees visibility and ordering for a single variable: writes by one thread become visible to others, and reads/writes are not reordered across that variable. It does NOT make compound actions atomic (like ++), nor does it protect invariants across multiple variables. Use locks or atomics for atomicity and compound state changes.
Practice Sets
This question appears in the following practice sets:
