为什么volatile限定符通过std :: atomic使用? [英] Why is the volatile qualifier used through out std::atomic?

查看:373
本文介绍了为什么volatile限定符通过std :: atomic使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我从 Herb Sutter 中阅读的内容, 其他认为 volatile 和并发编程是完全正交的概念,至少就C / C ++而言。

From what I've read from Herb Sutter and others you would think that volatile and concurrent programming were completely orthogonal concepts, at least as far as C/C++ are concerned.

但是,在GCC中 c ++ 0x扩展所有 std :: atomic 的成员函数具有 volatile 限定符。在Anthony Williams的实施 std ::原子

However, in GCC c++0x extension all of std::atomic's member functions have the volatile qualifier. The same is true in Anthony Williams's implementation of std::atomic.

那么什么处理,我的原子< volatile 还是不?

So what's deal, do my atomic<> variables need be volatile or not?

推荐答案

。请参见此处

相关的引用是


函数和操作被定义为使用volatile对象,应该是volatile也可以是atomic。然而,挥发性限定符对于原子性不是必需的。

The functions and operations are defined to work with volatile objects, so that variables that should be volatile can also be atomic. The volatile qualifier, however, is not required for atomicity.

没有,原子对象不一定是不稳定的。

And no, atomic objects don't have to be volatile.

这篇关于为什么volatile限定符通过std :: atomic使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆