It may fail doesn't mean that it will fail, on all machines. If you're running on a single core, for example, it probably won't fail. If you're running on a multicore Alpha, it almost certainly will fail some of the time. On other machines, the results will vary, depending on any number of things.
As for volatile
, it offers no guarantees for multi-threaded
code. It may be necessary if you're also using inline
assembler, or other things the compiler can't understand, but
otherwise: any time you do what ever else is necessary to ensure
thread safety, you don't need volatile
. In particular, if you
use the C++11 atomic types or threading primitives, volatile
is never necessary.