论文标题
有关事物的分离:使用C/C ++内存模型定义和编程的更简单基础(扩展版本)
Separation of concerning things: a simpler basis for defining and programming with the C/C++ memory model (extended version)
论文作者
论文摘要
C/C ++内存模型为并发(共享可变性)代码的程序员提供了接口和执行模型。它提供了一系列机制,这些机制从基础硬件内存模型中抽象出来,这些机制控制了多项架构如何处理与主内存的并发访问以及从编译器转换中抽象的。 C标准用事件之间的跨线程关系描述了内存模型,并受到类似基于的几项研究工作的影响。在本文中,我们为C内存模型的基本原理提供了线程定义,该定义对于简明的并发代码,它是相对直接的关于C排序机制影响的基础。我们认为,从编程的角度来看,该定义更为实用,并且可以通过已经建立的并发代码的技术进行分析。关键方面是,内存模型的定义与富含编程语言(尤其是C的表达评估和优化)的其他考虑因素分开,尽管我们展示了在存在C并发存在的情况下如何推理这些考虑因素。与C标准和文献中相关工作的描述相比,我们的框架的重大简化是分开围绕“缺乏多拷贝原子性”的考虑,这在任何情况下与X86,ARM,RISC-,RISC-V或SPARC体系结构的代码开发人员无关。我们展示了该框架如何方便地推理结构良好的代码,并正式解决了诸如“无薄空”的不直觉行为。
The C/C++ memory model provides an interface and execution model for programmers of concurrent (shared-variable) code. It provides a range of mechanisms that abstract from underlying hardware memory models -- that govern how multicore architectures handle concurrent accesses to main memory -- as well as abstracting from compiler transformations. The C standard describes the memory model in terms of cross-thread relationships between events, and has been influenced by several research works that are similarly based. In this paper we provide a thread-local definition of the fundamental principles of the C memory model, which, for concise concurrent code, serves as a basis for relatively straightforward reasoning about the effects of the C ordering mechanisms. We argue that this definition is more practical from a programming perspective and is amenable to analysis by already established techniques for concurrent code. The key aspect is that the memory model definition is separate to other considerations of a rich programming language such as C, in particular, expression evaluation and optimisations, though we show how to reason about those considerations in the presence of C concurrency. A major simplification of our framework compared to the description in the C standard and related work in the literature is separating out considerations around the "lack of multicopy atomicity", a concept that is in any case irrelevant to developers of code for x86, Arm, RISC-V or SPARC architectures. We show how the framework is convenient for reasoning about well-structured code, and for formally addressing unintuitive behaviours such as "out-of-thin-air" writes.