Click here to Skip to main content
15,890,995 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
Quote:
T operator=( T desired );
T operator=( T desired ) volatile;

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]
Posted
Updated 4-Jul-16 23:38pm

1 solution

Yes. And you should implement both operators. Pay attention, that the volatile type needs some syncronization details to ensure atomic access.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900