Separation of concerning things: a simpler basis for defining and programming with the C/C++ memory model (extended version)

R. Colvin
{"title":"Separation of concerning things: a simpler basis for defining and programming with the C/C++ memory model (extended version)","authors":"R. Colvin","doi":"10.48550/arXiv.2204.03189","DOIUrl":null,"url":null,"abstract":"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.","PeriodicalId":198480,"journal":{"name":"IEEE International Conference on Formal Engineering Methods","volume":"42 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2022-04-07","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"IEEE International Conference on Formal Engineering Methods","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.48550/arXiv.2204.03189","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0

Abstract

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.
有关事物的分离:用C/ c++内存模型定义和编程的更简单的基础(扩展版本)
C/ c++内存模型为并发(共享变量)代码的程序员提供了接口和执行模型。它提供了一系列从底层硬件内存模型中抽象出来的机制——这些模型控制着多核架构如何处理对主存的并发访问——以及从编译器转换中抽象出来的机制。C标准根据事件之间的跨线程关系来描述内存模型,并受到一些类似研究工作的影响。在本文中,我们提供了C内存模型基本原则的线程局部定义,对于简洁的并发代码,它可以作为关于C排序机制影响的相对直接推理的基础。我们认为,从编程的角度来看,这个定义更实用,并且可以通过已经建立的并发代码技术进行分析。关键的方面是,内存模型的定义与丰富的编程语言(如C)的其他考虑是分开的,特别是表达式求值和优化,尽管我们展示了如何在C并发的情况下对这些考虑进行推理。与C标准中的描述和文献中的相关工作相比,我们的框架的一个主要简化是将“缺乏多副本原子性”的考虑分离出来,这个概念在任何情况下都与x86, Arm, RISC-V或SPARC架构的代码开发人员无关。我们展示了该框架是如何方便地对结构良好的代码进行推理,以及如何正式地处理非直观的行为,如“凭空”编写。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信