相关事物的分离:使用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-V或RISC-V架构的代码开发人员无关。我们展示了框架是如何方便的推理结构良好的代码,并正式解决不直观的行为,如“出薄空气”写。
英文摘要:
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.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。