It depends on whether there is any other data that is shared between the threads. The problem with threads is that one thread may see writes from a different thread in a different order than the thread originally made them in. In that case you need to use some kind of _Interlocked*/Atomic function or locks (in both threads), they guarantee that all changes made before the flag become visible to the other thread.
If there is no other shared data (or only read-only shared data), or you are running on x86, using just volatile
should also work. However that it works is in a sense only accidentally, and not guaranteed by any standard, so if your platform supports it it is still advised to use some form of Atomic/interlocked/etc. In the future (i.e. once there is good compiler support) you should use C++11's std::atomcic
as that will be portable between platforms.
You should not be using a bare non-volatile variable, if you do that the compiler may decide to optimize the check away. volatile
has very little to do with caching as camelccc suggests.