Timothy is correct. Unless the variable is declared volatile the compiler is free to generate code that stores the int in a register and thus never sees the update to the variable in memory.