In some cases you might need to declare the variable "volatile", to make sure it is read from memory each time it's used and not stored in a CPU register. In case of several CPU cores, changes to one register might not be immediately visible to other cores (and thus, threads). Declaring a variable volatile tells the compiler not to keep it in CPU registers.