Quantcast
Channel: Is volatile required here - Stack Overflow
Browsing latest articles
Browse All 7 View Live

Answer by cmaster - reinstate monica for Is volatile required here

Don't use volatile, use std::atomic<>. volatile is designed and meant to be used for interacting with memory mapped hardware, std::atomic<> is designed and meant to be used for thread...

View Article



Answer by Lundin for Is volatile required here

The answer it: it depends. Do you have a reason to suspect that your compiler is not aware that code executed from within callback functions can be executed at any time? This is usually not the case on...

View Article

Answer by bartop for Is volatile required here

As said Is volatile required here - You sholud not use volatile for inter-thread synchronization. Here is why (from C++ standard):[..] volatile is a hint to the implementation to avoid aggressive...

View Article

Answer by Mário Feroldi for Is volatile required here

The actual problem is that reading from some memory (data in this case) while it's being written to is described as a data race, and therefore the behavior of the program is undefined. Even if you make...

View Article

Answer by Jive Dadson for Is volatile required here

If code is to be portable, volatile is never appropriate unless dealing with memory-mapped hardware. I repeat, never appropriate. Microsoft Visual C++, (x86 or x86/64), using the default compiler...

View Article


Answer by Andriy Berestovskyy for Is volatile required here

1) must seq be volatile in this context?Sure, most probably the read from seq will be optimized out with -O3. So yes, you should hint the compiler that seq might be changed elsewhere (i.e. in other...

View Article

Is volatile required here

I'm implementing a 'sequence lock' class to allow locked write and lock-free reads of a data structure.The struct that will contain the data contains the sequence value, which will be incremented twice...

View Article
Browsing latest articles
Browse All 7 View Live




Latest Images