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

后端 未结 5 885
渐次进展
渐次进展 2021-01-04 10:25

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 memo

5条回答
  •  被撕碎了的回忆
    2021-01-04 11:04

    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 variable.

    For atomic you will need to check your compiler's documentation to see if it provides any assistance or declaratives, or pragmas.

提交回复
热议问题