Quantcast
Channel: Is volatile a proper way to make a single byte atomic in C/C++? - Stack Overflow
Browsing all 6 articles
Browse latest View live

Answer by R.. GitHub STOP HELPING ICE for Is volatile a proper way to make a...

On any sane cpu, reading and writing any aligned, word-size-or-smaller type is atomic. This is not the issue. The issues are:Just because reads and writes are atomic, it does not follow that...

View Article


Answer by doron for Is volatile a proper way to make a single byte atomic in...

Short answer : Don't use volatile to guarantee atomicity.Long answerOne might think that since CPUs handle words in a single instruction, simple word operations are inherently thread safe. The idea of...

View Article


Answer by Thomas Matthews for Is volatile a proper way to make a single byte...

The volatile keyword is used to indicate that a variable (int, char, or otherwise) may be given a value from an external, unpredictable source. This usually deters the compiler from optimizing out the...

View Article

Answer by Omnifarious for Is volatile a proper way to make a single byte...

Not only does the standard not say anything about atomicity, but you are likely even asking the wrong question.CPUs typically read and write single bytes atomically. The problem comes because when you...

View Article

Answer by Oliver Charlesworth for Is volatile a proper way to make a single...

The standard says nothing about atomicity.

View Article


Is volatile a proper way to make a single byte atomic in C/C++?

I know that volatile does not enforce atomicity on int for example, but does it if you access a single byte? The semantics require that writes and reads are always from memory if I remember...

View Article
Browsing all 6 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>