1 -------------------------------------------------------------------------------
3 -------------------------------------------------------------------------------
5 [refer to release sequence notes for some definitions and similar (but simpler)
8 Fences provide a few new modification order constraints as well as an
9 interesting extension to release sequences, detailed in 29.3 (p4-p7) and 29.8
12 Section 29.3 details the modification order constraints established by
13 sequentially-consistent fences.
15 Section 29.8 details the behavior of release and acquire fences (note that
16 memory_order_seq_cst is both release and acquire).
18 The text of these rules are provided at the end of this document for reference.
20 *******************************
21 Backtracking requirements
22 *******************************
24 Because we maintain the seq-cst order as consistent with the execution order,
25 seq-cst fences cannot commute with each other, with seq-cst loads, nor with
26 seq-cst stores; we backtrack at all such pairs.
28 Fences extend release/acquire synchronization beyond just
29 store-release/load-acquire. We must backtrack with potentially-synchronizing
30 fences: that is, with any pair of store- or fence-release and load- or
31 fence-acquire, where the release comes after the acquire in the execution order
32 (the other ordering is OK, as we will explore both behaviors; where the pair
33 synchronize and where they don't).
35 Note that, for instance, a fence-release may synchronize with a fence-acquire
36 only in the presence of a appropriate load/store pair (29.8p2); but the
37 synchronization still occurs between the fences, so the backtracking
38 requirements are only placed on the release/acquire fences themselves.
40 *******************************
41 Seq-cst MO constraints (29.3 p4-p7)
42 *******************************
44 The statements given in the specification regarding sequentially consistent
45 fences can be transformed into the following 4 modification order constraints.
50 is_write(A) && is_read(B) && is_write(X) && is_fence(Y) &&
51 is_seqcst(X) && is_seqcst(Y) && A != X &&
58 Intuition/Implementation:
59 * We may (but don't currently) limit our considertion of X to only the most
60 recent (in the SC order) store to the same location as A and B prior to Y
61 (note that all prior writes will be ordered prior to X in both SC and MO)
62 * We should consider the "most recent" seq-cst fence Y that precedes B
63 * This search can be combined with the r_modification_order search, since we
64 already iterate through the necessary stores X
69 is_write(A) && is_read(B) && is_write(X) && is_fence(Y) &&
70 is_seqcst(B) && is_seqcst(Y) &&
78 Intuition/Implementation:
79 * We only need to examine the "most recent" seq-cst fence Y from each thread
80 * We only need to examine the "most recent" qualifying store X that precedes Y;
81 all other X will provide a weaker MO constraint
82 * This search can be combined with the r_modification_order search, since we
83 already iterate through the necessary stores X
85 For atomic operations A and B on an atomic object M, where A modifies M and B
86 takes its value, if there is a memory_order_seq_cst fence X such that A is
87 sequenced before X and B follows X in S, then B observes either the effects of
88 A or a later modification of M in its modification order.
93 is_write(A) && is_read(B) && is_write(X) && is_fence(Y) && is_fence(Z) &&
94 is_seqcst(Y) && is_seqcst(Z) &&
98 X --sb-> Y --sc-> Z --sb-> B
102 Intuition/Implementation:
103 * We should consider only the "most recent" fence Z in the same thread as B
104 (prior fences may only yield the same or weaker constraints)
105 * We may then consider the "most recent" seq-cst fence Y prior to Z (in SC order)
106 from each thread (prior fences may only yield the same or weaker constraints)
107 * We should consider only the "most recent" store X (to the same location as A,
108 B) in the same thread as Y (prior stores may only yield the same or weaker
110 * This search can be combined with the r_modification_order search, since we
111 already iterate through the necessary stores X
116 is_write(A) && is_write(B) && is_fence(X) && is_fence(Y) &&
117 is_seqcst(X) && is_seqcst(Y) &&
119 A --sb-> X --sc-> Y --sb-> B
123 Intuition/Implementation:
124 * (Similar to 29.3p6 rules, except using A/B write/write) only search for the
125 most recent fence Y in the same thread; search for the most recent (prior to
126 Y) fence X from each thread; search for the most recent store A prior to X
127 * This search can be combined with the w_modification_order search, since we
128 already iterate through the necessary stores A
130 **********************************************************************
131 Release/acquire synchronization: extended to fences (29.3 p4-p7)
132 **********************************************************************
137 *******************************
139 *******************************
141 fence(memory_order_consume) acts like memory_order_release, so if we ever
142 support consume, we must alias consume -> release
144 fence(memory_order_relaxed) is a no-op
146 *******************************
147 Approximate Algorithm [incomplete; just copied from the (out-of-date) release
149 *******************************
151 Check read-write chain...
154 current action = curr
157 * rf is NULL: return uncertain
160 add rf to release heads
162 return certain [note: we don't need to extend release sequence
163 further because this acquire will have synchronized already]
165 return (recursively) "get release sequence head of rf"
167 add rf to release heads
169 * else, rf is relaxed write (NOT RMW)
172 **************************************
173 From the C++11 specification (N3337)
174 **************************************
182 For an atomic operation B that reads the value of an atomic object M, if there
183 is a memory_order_seq_cst fence X sequenced before B, then B observes either
184 the last memory_order_seq_cst modification of M preceding X in the total order
185 S or a later modification of M in its modification order.
189 For atomic operations A and B on an atomic object M, where A modifies M and B
190 takes its value, if there is a memory_order_seq_cst fence X such that A is
191 sequenced before X and B follows X in S, then B observes either the effects of
192 A or a later modification of M in its modification order.
196 For atomic operations A and B on an atomic object M, where A modifies M and B
197 takes its value, if there are memory_order_seq_cst fences X and Y such that A
198 is sequenced before X, Y is sequenced before B, and X precedes Y in S, then B
199 observes either the effects of A or a later modification of M in its
204 For atomic operations A and B on an atomic object M, if there are
205 memory_order_seq_cst fences X and Y such that A is sequenced before X, Y is
206 sequenced before B, and X precedes Y in S, then B occurs later than A in the
207 modification order of M.
215 A release fence A synchronizes with an acquire fence B if there exist atomic
216 operations X and Y, both operating on some atomic object M, such that A is
217 sequenced before X, X modifies M, Y is sequenced before B, and Y reads the value
218 written by X or a value written by any side effect in the hypothetical release
219 sequence X would head if it were a release operation.
223 A release fence A synchronizes with an atomic operation B that performs an
224 acquire operation on an atomic object M if there exists an atomic operation X
225 such that A is sequenced before X, X modifies M, and B reads the value written
226 by X or a value written by any side effect in the hypothetical release sequence
227 X would head if it were a release operation.
231 An atomic operation A that is a release operation on an atomic object M
232 synchronizes with an acquire fence B if there exists some atomic operation X on
233 M such that X is sequenced before B and reads the value written by A or a value
234 written by any side effect in the release sequence headed by A.