简体   繁体   English

C ++ 11标准是否正式定义了获取,发布和使用操作?

[英]Does the C++11 standard formally define acquire, release, and consume operations?

In the C++11 standard, section 1.10/5 mentions, but does not formally define the terms acquire operation , release operation , and consume operation . 在C ++ 11标准中,第1.10 / 5节提到,但没有正式定义术语acquire operationrelease operationconsume 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. 然后在第29节继续使用这些术语来描述某些内存排序,原子操作和内存栅栏的操作。 For instance, 29.3/1 on "Order and Consistency" states: 例如,关于“顺序和一致性”的29.3 / 1表示:

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. memory_order_releasememory_order_acq_relmemory_order_seq_cst :存储操作在受影响的内存位置上执行释放操作 [强调添加]。

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. 这种类型的语言在第29节中重复出现,但令我memory_order是, memory_order枚举的所有含义都基于操作类型,这些操作类型本身似乎没有被标准形式化,但必须具有一些共同的意义。它们作为定义有效。

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. 换句话说,如果我说“一个酒吧是一个翻转的foo”, barfoo的具体含义是模棱两可的,因为这两个术语都没有正式定义。 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? C ++ 11标准或其他一些C ++ 11标准委员会文档是否正式定义了acquire operationrelease operation等的确切内容,或者这些是通常理解的术语? 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. 我特别要求,因为硬件内存一致性模型不是相同的,因此我认为必须有一些共同商定的引用,允许那些实现编译器等的人正确地将这些操作的语义转换为本机程序集命令。

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 on A . A执行释放操作会强制对其他存储器位置的先​​前副作用对其他线程可见,以便稍后对A执行消耗或获取操作。

Besides that, the behavior of acquire and release operations is fully defined in 1.10, specifically in how they contribute to happens-before relationships. 除此之外,获取和释放操作的行为在1.10中完全定义,特别是它们如何关系之前发生 Any definition apart from behavior is useless. 除了行为之外的任何定义都是无用的。

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 . 这不是一个明确的参考,但Raymond Chen在博客上发表了关于获取/发布语义的文章 His post includes a link to Microsoft's definition of acquire and release semantics , which you might also find useful. 他的帖子包含了微软对获取和发布语义的定义的链接 ,您可能也会发现它很有用。

actually these operations are defined in section 1.10/5-12. 实际上,这些操作在1.10 / 5-12节中定义。

release/acquire pair corresponds to the happen before relationship; release/acquire对对应于关系之前发生 ; while release/consume pair to the dependency-ordered before relationship. release/consume关系之前依赖于顺序排列

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. 但是,我认为第1.10节第5和第6节似乎与我在其他语言标准中读取的所有获取/释放语义定义以及CPU定义相匹配。

Regardless, one of the major points of C++11 was to define a modern memory model to support concurrent and multi-threaded code. 无论如何,C ++ 11的一个主要观点是定义一个现代内存模型来支持并发和多线程代码。 I find it hard to believe they didn't get it right :) 我发现很难相信他们没有把它弄好:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM