I'm guessing it's because of the compiler's optimization steps.

Try declaring state and goFlag as volatile. If that doesn't work, please post more complete code so we can try it out and see what's...