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.

50<br />

sublanguages <strong>and</strong> the related parts of the model that each section introduces:<br />

Section sublanguage<br />

elements of model introduced<br />

§3.1 single threaded (no locks, no atomics, no<br />

fences)<br />

top-level model structure, sequenced-before<br />

§3.2 concurrent with locks lock-order, synchronises-with, data races<br />

§3.3 concurrent with relaxed atomics <strong>and</strong> locks atomics, modification order, coherence, CAS<br />

§3.4 concurrent with release <strong>and</strong> acquire atomics<br />

<strong>and</strong> locks (no relaxed atomics)<br />

release-acquire synchronisation<br />

§3.5 release, acquire <strong>and</strong> relaxed atomics <strong>and</strong> locks release sequences<br />

§3.6 all of the above plus release <strong>and</strong> acquire fences hypothetical release sequences<br />

§3.7 all of the above plus SC atomics SC-order<br />

§3.8 all of the above plus SC fences SC fence restrictions<br />

§3.9 all of the above plus consume atomics (locks,<br />

all atomics, all fences)<br />

data-dependence, carries-a-dependency-to,<br />

dependency-ordered-before<br />

§3.10 locks, all atomics, all fences visible-sequences-of-side-effects<br />

3.1 Top-level structure by example: single-threaded programs<br />

Before introducing the memory model that governs simple single-threaded programs, it is<br />

necessary to formally define the top-level structure <strong>and</strong> underlying types of the memory<br />

model. We start with the type of actions.<br />

Memory actions Reads <strong>and</strong> writes to memory, locks, unlocks <strong>and</strong> fences are modelled<br />

by memory events called actions. <strong>The</strong> action type is given below. Each action has a<br />

unique action-identifier, of type aid, <strong>and</strong> a thread identifier, of type tid, identifying its<br />

host thread.<br />

type action =<br />

| Lock of aid ∗ tid ∗ location ∗ lock outcome<br />

| Unlock of aid ∗ tid ∗ location<br />

| Load of aid ∗ tid ∗ memory order ∗ location ∗ cvalue<br />

| Store of aid ∗ tid ∗ memory order ∗ location ∗ cvalue<br />

| RMW of aid ∗ tid ∗ memory order ∗ location ∗ cvalue ∗ cvalue<br />

| Fence of aid ∗ tid ∗ memory order<br />

| Blocked rmw of aid ∗ tid ∗ location<br />

Locks have an outcome <strong>and</strong> can either leave the mutex Locked or Blocked:<br />

type lock outcome =<br />

Locked<br />

| Blocked

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

Saved successfully!

Ooh no, something went wrong!