问题描述
我需要有原子变量在我的计划。 previously我使用的std ::原子< INT>
,但在我现在的工作平台不具有支持C ++ 0x开头的G ++编译器。我用挥发性INT
,它似乎是工作,因为我还没有在多核系统我测试它经历了一个竞争条件呢。
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.
我的问题是,如果挥发性INT
为原子如的std ::原子&LT; INT&GT;
?同时,它会创建内存屏障(这也是我需要)?
My question is if volatile int
is atomic like std::atomic<int>
? Also, does it creates memory barriers (which I also require)?
推荐答案
我见过你问GCC的一些意见,在这里你去。
I've seen you asking about GCC in some comments, here you go.
这篇关于在C挥发性INT不如的std ::原子&LT; INT&GT;中的C ++ 0x?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!