|
1 | 1 | # Atomics
|
2 | 2 |
|
3 |
| -Rust pretty blatantly just inherits C11's memory model for atomics. This is not |
| 3 | +Rust pretty blatantly just inherits the memory model for atomics from C++20. This is not |
4 | 4 | due to this model being particularly excellent or easy to understand. Indeed,
|
5 | 5 | this model is quite complex and known to have [several flaws][C11-busted].
|
6 | 6 | Rather, it is a pragmatic concession to the fact that *everyone* is pretty bad
|
7 | 7 | at modeling atomics. At very least, we can benefit from existing tooling and
|
8 |
| -research around C. |
| 8 | +research around the C/C++ memory model. |
9 | 9 |
|
10 | 10 | Trying to fully explain the model in this book is fairly hopeless. It's defined
|
11 | 11 | in terms of madness-inducing causality graphs that require a full book to
|
12 | 12 | properly understand in a practical way. If you want all the nitty-gritty
|
13 |
| -details, you should check out [C's specification (Section 7.17)][C11-model]. |
| 13 | +details, you should check out the [C++20 draft specification (Section 31)][C++-model]. |
14 | 14 | Still, we'll try to cover the basics and some of the problems Rust developers
|
15 | 15 | face.
|
16 | 16 |
|
17 |
| -The C11 memory model is fundamentally about trying to bridge the gap between the |
| 17 | +The C++ memory model is fundamentally about trying to bridge the gap between the |
18 | 18 | semantics we want, the optimizations compilers want, and the inconsistent chaos
|
19 | 19 | our hardware wants. *We* would like to just write programs and have them do
|
20 | 20 | exactly what we said but, you know, fast. Wouldn't that be great?
|
@@ -113,7 +113,7 @@ programming:
|
113 | 113 |
|
114 | 114 | # Data Accesses
|
115 | 115 |
|
116 |
| -The C11 memory model attempts to bridge the gap by allowing us to talk about the |
| 116 | +The C++ memory model attempts to bridge the gap by allowing us to talk about the |
117 | 117 | *causality* of our program. Generally, this is by establishing a *happens
|
118 | 118 | before* relationship between parts of the program and the threads that are
|
119 | 119 | running them. This gives the hardware and compiler room to optimize the program
|
@@ -148,7 +148,7 @@ propagated to other threads. The set of orderings Rust exposes are:
|
148 | 148 | * Acquire
|
149 | 149 | * Relaxed
|
150 | 150 |
|
151 |
| -(Note: We explicitly do not expose the C11 *consume* ordering) |
| 151 | +(Note: We explicitly do not expose the C++ *consume* ordering) |
152 | 152 |
|
153 | 153 | TODO: negative reasoning vs positive reasoning? TODO: "can't forget to
|
154 | 154 | synchronize"
|
@@ -252,4 +252,4 @@ relaxed operations can be cheaper on weakly-ordered platforms.
|
252 | 252 |
|
253 | 253 |
|
254 | 254 | [C11-busted]: http://plv.mpi-sws.org/c11comp/popl15.pdf
|
255 |
| -[C11-model]: http://www.open-std.org/jtc1/sc22/wg14/www/standards.html#9899 |
| 255 | +[C++-model]: http://eel.is/c++draft/atomics.order |
0 commit comments