volatile
volatile is a keyword in some programming languages such as C, C++, C# and Java.
It suppress compiler optimization.
ANSI C (C89) has it in its standard.
In multi-threaded context, seemingly useless evaluation of a variable was actually meaningful because interruption or other threads could alter the value. Compilers assume external context won’t change variables.
In C, it directs compiler not to keep the variable on CPU register.
It is like a light-weight version of synchronized.
In Java, a compiler may optimize memory usage where a variable is kept. If a variable is kept on working memory, it may cause inconsistency between threads. By adding volitile keyword, it is guaranteed to have value synchronized between threads.
