diff options
author | pierre Kuo <vichy.kuo@gmail.com> | 2017-04-07 02:37:36 -0400 |
---|---|---|
committer | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2017-04-12 11:23:43 -0400 |
commit | b26cfc48e3e03126c183f1f3960e6d69460bb852 (patch) | |
tree | ea7929ee20ba916595758350c958d1d81594d1e6 | |
parent | d3d3a3ccc4a8f1f254fb6788081f35bebe374174 (diff) |
doc: Update control-dependencies section of memory-barriers.txt
In the following example, if MAX is defined to be 1, then the compiler
knows (Q % MAX) is equal to zero. The compiler can therefore throw
away the "then" branch (and the "if"), retaining only the "else" branch.
q = READ_ONCE(a);
if (q % MAX) {
WRITE_ONCE(b, 1);
do_something();
} else {
WRITE_ONCE(b, 2);
do_something_else();
}
It is therefore necessary to modify the example like this:
q = READ_ONCE(a);
- WRITE_ONCE(b, 1);
+ WRITE_ONCE(b, 2);
do_something_else();
Signed-off-by: pierre Kuo <vichy.kuo@gmail.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
-rw-r--r-- | Documentation/memory-barriers.txt | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Documentation/memory-barriers.txt b/Documentation/memory-barriers.txt index d2b0a8d81258..08329cb857ed 100644 --- a/Documentation/memory-barriers.txt +++ b/Documentation/memory-barriers.txt | |||
@@ -768,7 +768,7 @@ equal to zero, in which case the compiler is within its rights to | |||
768 | transform the above code into the following: | 768 | transform the above code into the following: |
769 | 769 | ||
770 | q = READ_ONCE(a); | 770 | q = READ_ONCE(a); |
771 | WRITE_ONCE(b, 1); | 771 | WRITE_ONCE(b, 2); |
772 | do_something_else(); | 772 | do_something_else(); |
773 | 773 | ||
774 | Given this transformation, the CPU is not required to respect the ordering | 774 | Given this transformation, the CPU is not required to respect the ordering |