Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does C++11 allow (not require) release/acquire semantics for volatile keyword

Since Visual C++ 2005, Microsoft has made additional ordering guarantees for accesses to volatile types which are not required by the C++ Standard.

Does anything in the C++ Standard actually forbid these guarantees? The Microsoft documentation seems to think so.

Please let me know whether the Standard allows the ordering implemented by Microsoft, and also vote on this bug report:

  • /volatile:ms documentation mangles what "ISO compliant" means
like image 450
Ben Voigt Avatar asked Oct 15 '12 16:10

Ben Voigt


People also ask

What is acquire and release semantics?

An operation has acquire semantics if other processors will always see its effect before any subsequent operation's effect. An operation has release semantics if other processors will see every preceding operation's effect before the effect of the operation itself.

What does volatile keyword do in C++?

Volatile is a qualifier that is applied to a variable when it is declared. It tells the compiler that the value of the variable may change at any time-without any action being taken by the code the compiler finds nearby.

Is volatile atomic in C?

In C and C++Operations on volatile variables are not atomic, nor do they establish a proper happens-before relationship for threading.


1 Answers

An implementation is certainly allowed to do things beyond on what is required as long as it meets the requirements set forth by the standard. Adding release/acquire semantics to volatile object is definitely within scope. I don't think there is interest in the C++ committee to change the semantics (we are just starting a new week of discussing C++ in Portland with Herb right now talking about how to organize the meeting).

like image 157
Dietmar Kühl Avatar answered Sep 20 '22 16:09

Dietmar Kühl