Why Is Volatile Not Enough for Interrupt-Shared Data?
A volatile qualifier makes the compiler perform accesses to a shared variable.
The key idea
A volatile qualifier makes the compiler perform accesses to a shared variable. An interrupt can still occur partway through a multi-instruction update.
What to remember
- Distinguish visibility from atomicity
- Choose synchronization suited to the processor and data width
Check your understanding
Can an interrupt interrupt a volatile counter increment?
Show the explanation
Yes. A read, addition and write can be separate instructions.