> -----Original Message-----
> From: interest-bounces+kai.koehne=digia....@qt-project.org
> [mailto:interest-bounces+kai.koehne=digia....@qt-project.org] On Behalf Of
> Bob Hood
> Sent: Monday, March 24, 2014 4:49 PM
> To: Thiago Macieira; interest@qt-project.org
> Subject: Re: [Interest] QThread
> 
> [...]
> I actually use the "volatile" tag to tell the compiler that it cannot 
> optimize (i.e.,
> make compile-time assumptions about) the variable that it decorates.
> Does std::atomic have the same meaning for optimizations?  I can't get a clear
> picture of this by a (cursory) Google.

To cite
https://stackoverflow.com/questions/12878344/volatile-in-c11

" Now, let's look at what C++11 says about volatile int x;. If you put that in 
there, and you have some other thread mess with x, you still have undefined 
behavior. Volatile does not affect threading behavior. C++11's memory model 
does not define reads or writes from/to x to be atomic, nor does it require the 
memory barriers needed for non-atomic reads/writes to be properly ordered. 
volatile has nothing to do with it one way or the other.

Oh, your code might work. But C++11 doesn't guarantee it.

What volatile tells the compiler is that it can't optimize memory reads from 
that variable. However, CPU cores have different caches, and most memory writes 
do not immediately go out to main memory. They get stored in that core's local 
cache, and may be written... eventually."


Regards

Kai 
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to