I need to have atomic variables in my program. Previously I was using std::atomic<int>
, but the platform in which I'm working now does not have a g++ compiler that supports C++0x. I used volatile int
and it seems to be working, as I haven't experienced a race condition yet in the multicore system I'm testing it on.
My question is if volatile int
is atomic like std::atomic<int>
? Also, does it creates memory barriers (which I also require)?
atomic<>
at all? ;) The usual rule of thumb applies, that the language designers aren't completely insane, so there's probably some reason for what they do :) – Frobisheratomic
). But there is no problem statement in your question, and so there is no room for a "solution". Are you looking for something like "no,volatile
isn't suitable here, so you need to either usestd::atomic
, or use a proper memory barrier"? If so, then that's your answer. :) – Frobisher