Reputation: 32490
In the C++11 standard, section 1.10/5 mentions, but does not formally define the terms acquire operation
, release operation
, and consume operation
. It then goes on in Section 29 to use these terms to describe the actions of certain memory orderings, atomic operations, and memory fences. For instance, 29.3/1 on "Order and Consistency" states:
memory_order_release, memory_order_acq_rel, and memory_order_seq_cst: a store operation performs a release operation [emphasis added] on the affected memory location.
This type of language is repeated throughout section 29, but it bothers me a bit that all meanings for the memory_order
enumerations are based on operation types that themselves do not seem to be formalized by the standard, yet must have some commonly agreed-to meaning for them to be effective as definitions.
Put a different way, if I said "A bar is a flipped foo", the concrete meaning of bar and foo are ambiguous since neither term is formally defined. Only their relative natures are defined.
Does the C++11 standard, or some other C++11 standards committee document formally define what exactly an acquire operation
, release operation
, etc. is, or are these simply commonly understood terms? If the latter, is there a good reference that is considered an industry standard for the meaning of these operations? I specifically ask because hardware memory consistency models are not created equal, and therefore I'm figuring there must be some commonly agreed-to reference that allows those implementing compilers, etc. to properly translate the semantics of these operations into native assembly commands.
Upvotes: 22
Views: 1332
Reputation: 283624
There's an informal summarized definition given in one of the notes:
performing a release operation on
A
forces prior side effects on other memory locations to become visible to other threads that later perform a consume or an acquire operation onA
.
Besides that, the behavior of acquire and release operations is fully defined in 1.10, specifically in how they contribute to happens-before relationships. Any definition apart from behavior is useless.
Upvotes: 6
Reputation: 827
actually these operations are defined in section 1.10/5-12.
release/acquire
pair corresponds to the happen before relationship; while release/consume
pair to the dependency-ordered before relationship.
Upvotes: 3
Reputation: 35881
I also take acquire/release semantics to be fairly definitive on it's own; although they're more hardware specific terms historically rather than programming terms.
But, I think section 1.10 para 5 and 6 seem to match all acquire/release semantics definitions I've read in other language standards as well as CPU definitions.
Regardless, one of the major points of C++11 was to define a modern memory model to support concurrent and multi-threaded code. I find it hard to believe they didn't get it right :)
Upvotes: 0
Reputation: 35914
I don't see any formal definition of acquire/release semantics after a quick look through the standard, so my guess is that they are assumed to be commonly understood terms.
They can't define everything, after all.
It's not a definitive reference, but Raymond Chen has blogged about acquire/release semantics. His post includes a link to Microsoft's definition of acquire and release semantics, which you might also find useful.
Upvotes: 3