我需要用VOLATILE标记STD :: ATOMIC吗? [英] Do I need to mark STD::ATOMIC with VOLATILE?

查看:134
本文介绍了我需要用VOLATILE标记STD :: ATOMIC吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前用过 volatilce cv AND std :: atomic class separtaley ,现在我很奇怪,我应该合并它们以确保正确访问吗?



一般来说,假设我有一些全局静态原子标志,它是否是 std :: atomic< bool> OR std :: atomic_flag ,并不重要(如我所见),我应该将其标记为 volatile



我看了 std :: atomic :: operator = description [ ^ ] AND 它有特定的volatile实现:

I am previously used both volatilce cv AND std::atomic class separtaley, now i'm wonder, should i am combine them in order to ensure the proper access?

In general, assuming i have some global-static atomic flag, whether it would be std::atomic<bool> OR std::atomic_flag, doesn't really matter (as i see it), should i mark it as volatile?

I looked at the std::atomic::operator= description[^] AND it has specific volatile realization:

引用:

T operator =(T desired);

T operator =(T desired)volatile;

T operator=( T desired );
T operator=( T desired ) volatile;



作为 volatile 使用合格的成员函数w ith volatile 个实例( volatile:多线程程序员最好的朋友 Andrei Alexandrescu )设计了这样一个类接口,假设为了某些目的,会创建类的 volatile 对象,所以显然有一些原因可以存在。



我尝试了什么:



,我理解 volatile vs atomic diffirence [例如, volatile vs. volatile ,By < b> Herb Sutter ]


As the volatile qualified member function is used with the volatile instances ("volatile: The Multithreaded Programmer's Best Friend", By Andrei Alexandrescu), those who had designed such a class interface was supposed there would be volatile objects of the class created, for some purpose, so there obviously some reasone to do that exist.

What I have tried:

YES, i am understanding volatile vs atomic diffirence [for example, "volatile vs. volatile", By Herb Sutter]

推荐答案

是的。你应该实现两个运营商。请注意,volatile类型需要一些同步化细节以确保原子访问。
Yes. And you should implement both operators. Pay attention, that the volatile type needs some syncronization details to ensure atomic access.


这篇关于我需要用VOLATILE标记STD :: ATOMIC吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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