I just asked a question involving volatile: volatile array c++
However my question spawned a discussion on what volatile
does.
Some claim that w
Can you ALWAYS be sure that thread 1 will stop if done is not
volatile
?
Always? No. But in this case the assignment to done
is in the same module, and the while
loop will probably not be optimized out. Depends on how the MSVC performs its optimizations.
Generally, it is safer to declare it with volatile
to avoid uncertainty with optimizations.