29.11.2015 Views

The C11 and C++11 Concurrency Model

1ln7yvB

1ln7yvB

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3<br />

<strong>The</strong> formal C/C++ memory model<br />

This chapter describes a mechanised formal definition of the C/<strong>C++11</strong> memory model,<br />

following the <strong>C++11</strong> st<strong>and</strong>ard (Appendix A establishes a close link to the text). <strong>The</strong><br />

formal model was developed in discussion with the <strong>C++11</strong> st<strong>and</strong>ardisation committee<br />

during the drafting phases of the <strong>C++11</strong> st<strong>and</strong>ard. This process brought to light several<br />

major errors in drafts of the st<strong>and</strong>ard <strong>and</strong> led to solutions that were incorporated in the<br />

ratified st<strong>and</strong>ards (Chapter 5 discusses these changes, together with remaining issues).<br />

<strong>The</strong> close contact with the st<strong>and</strong>ardisation committee, the link to the st<strong>and</strong>ard text <strong>and</strong><br />

the fact that this model fed changes to the st<strong>and</strong>ard establish it as an authoritative<br />

representation of the <strong>C++11</strong> memory model. <strong>C11</strong> adopts the same memory model as<br />

<strong>C++11</strong> for compatibility, so the model presented here applies to C as well.<br />

<strong>The</strong> formal model relies on several simplifications. Details like alignment, bit representation,<br />

<strong>and</strong> trap values are ignored, we assume variables are aligned <strong>and</strong> disjoint, signal<br />

h<strong>and</strong>lers are not modeled <strong>and</strong> neither is undefined behaviour introduced thread-locally:<br />

e.g. division by zero, out-of-bound array accesses. We do not consider mixed size accesses<br />

or allocation <strong>and</strong> deallocation of memory: both would require a memory-layout model<br />

that is omitted for simplicity.<br />

<strong>The</strong> memory model is introduced in stages, as a sequence of derivative models that<br />

apply to successively more complete sublanguages of C/<strong>C++11</strong>. <strong>The</strong> mathematics that<br />

describe the models is automatically typeset from the source, written in the Lem specification<br />

language [90] (the full set of definitions are reproduced in Appendix C). <strong>The</strong> first<br />

section introduces a cut-down version of the C/<strong>C++11</strong> memory model that describes the<br />

behaviour of straightforward single-threaded programs, <strong>and</strong> in doing so, introduces the<br />

underlying types <strong>and</strong> top-level structure of the memory model that will apply to the rest<br />

of the models in the chapter. This introductory section is followed by a series of formal<br />

memory models that incrementally introduce concurrency features, together with the<br />

mathematics that describe how they behave, <strong>and</strong> the underlying architectural intuitions<br />

related to them. <strong>The</strong> chapter culminates in the presentation of the full formal model of<br />

C/<strong>C++11</strong> concurrency as defined by the ISO st<strong>and</strong>ard. <strong>The</strong> following table displays the<br />

49

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!