Skip to content

Commit bc30521

Browse files
committed
---
yaml --- r: 222715 b: refs/heads/tmp c: 18067e4 h: refs/heads/master i: 222713: c8ef22d 222711: 48a1e99 v: v3
1 parent b28e430 commit bc30521

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: 2b45108ecb944d63daba0f1b5529ac4c8afdc295
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: 108a697b1c225dafef16a77076e30149b1d0ebe7
28+
refs/heads/tmp: 18067e41090938ff5d642bbef05604c939e542dc
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: e58601ab085591c71a27ae82137fc313222c2270
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/concurrency.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,44 @@ only to data races?
154154

155155
# Atomics
156156

157-
Rust pretty blatantly just inherits LLVM's model for atomics, which in turn is
158-
largely based off of the C11 model for atomics. This is not due these models
159-
being particularly excellent or easy to understand. Indeed, these models are
160-
quite complex and are known to have several flaws. Rather, it is a pragmatic
161-
concession to the fact that *everyone* is pretty bad at modeling atomics. At very
162-
least, we can benefit from existing tooling and research around C's model.
157+
Rust pretty blatantly just inherits C11's memory model for atomics. This is not
158+
due this model being particularly excellent or easy to understand. Indeed, this
159+
model is quite complex and known to have [several flaws][C11-busted]. Rather,
160+
it is a pragmatic concession to the fact that *everyone* is pretty bad at modeling
161+
atomics. At very least, we can benefit from existing tooling and research around
162+
C.
163163

164-
Trying to fully explain these models is fairly hopeless, so we're just going to
165-
drop that problem in LLVM's lap.
164+
Trying to fully explain the model is fairly hopeless. If you want all the
165+
nitty-gritty details, you should check out [C's specification][C11-model].
166+
Still, we'll try to cover the basics and some of the problems Rust developers
167+
face.
168+
169+
The C11 memory model is fundamentally about trying to bridge the gap between C's
170+
single-threaded semantics, common compiler optimizations, and hardware peculiarities
171+
in the face of a multi-threaded environment. It does this by splitting memory
172+
accesses into two worlds: data accesses, and atomic accesses.
173+
174+
Data accesses are the bread-and-butter of the programming world. They are
175+
fundamentally unsynchronized and compilers are free to aggressively optimize
176+
them. In particular data accesses are free to be reordered by the compiler
177+
on the assumption that the program is single-threaded. The hardware is also free
178+
to propagate the changes made in data accesses as lazily and inconsistently as
179+
it wants to other threads. Mostly critically, data accesses are where we get data
180+
races. These are pretty clearly awful semantics to try to write a multi-threaded
181+
program with.
182+
183+
Atomic accesses are the answer to this. Each atomic access can be marked with
184+
an *ordering*. The set of orderings Rust exposes are:
185+
186+
* Sequentially Consistent (SeqCst)
187+
* Release
188+
* Acquire
189+
* Relaxed
190+
191+
(Note: We explicitly do not expose the C11 *consume* ordering)
192+
193+
TODO: give simple "basic" explanation of these
194+
TODO: implementing Arc example (why does Drop need the trailing barrier?)
166195

167196

168197

@@ -184,5 +213,5 @@ with everyone else's stuff.
184213

185214

186215

187-
[llvm-conc]: http://llvm.org/docs/Atomics.html
188-
[trpl-conc]: https://doc.rust-lang.org/book/concurrency.html
216+
[C11-busted]: http://plv.mpi-sws.org/c11comp/popl15.pdf
217+
[C11-model]: http://en.cppreference.com/w/c/atomic/memory_order

0 commit comments

Comments
 (0)