Up Next

Fences

Equivalence of constructs

The comparison between C11 and Linux is based upon the following equivalence of constructs:

 LinuxC11
Ordinary storeWRITE_ONCEatomic store relaxed
Ordinary loadREAD_ONCEatomic load relaxed
Strong fencesmp_mb()SC Fence
Write to Write fencesmp_wmb()Release Acquire Fence
Read to Read fencesmp_rmb()Release Acquire Fence

Equating Linux concurrency aware memory accesses with (volatile) relaxed atomics sounds straightforward and prevents data races in the case of the C11 model. Similarly both models feature a strongest fence, which we equate.

The assimilation of C11 Release Acquire fence with both lighter fences (i.e. smp_wmb() and smp_rmb()) looks more arbitrary but remains a decent choice of assimilating all those fences to a “second to strongest” fence. The release-acquire fence of C11 is the “second to strongest” fence, as it must be stronger than both the release and acquire fences and lighter than the SC fence. Similarly, if we assimilate Linux two remaining fences as a unique fence, this hypothetical fence is the second strongest one.

C11 shows more behaviours

The table below shows that it does not suffice to insert SC fences in-between all pairs of memory accesses by the same thread to forbid non-SC behaviours. The two litmus tests RWC and IRIW are worth noticing. The first test RWC s of minimal size (five memory accesses performed by 3 three threads). The second test IRIW is the canonical example of non-multi-copy atomicity, which C11 “SC” fence fails to annihilate.

There are 13 such tests
 C11Model
RWC+fencembsAllowForbid
WRR+2W+fencembsAllowForbid
WRW+2W+fencembsAllowForbid
WRW+WR+fencembsAllowForbid
W+RWC+fencemb+fencermb+fencembAllowForbid
W+RWC+fencewmb+fencemb+fencembAllowForbid
Z6.0+fencewmb+fencemb+fencembAllowForbid
Z6.1+fencemb+fencewmb+fencembAllowForbid
Z6.3+fencemb+fencemb+fencermbAllowForbid
Z6.3+fencemb+fencewmb+fencembAllowForbid
IRIW+fencembsAllowForbid
IRRWIW+fencembsAllowForbid
IRWIW+fencembsAllowForbid

C11 shows less behaviours

There is no such test

Up Next