about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexis Beingessner <a.beingessner@gmail.com>2015-07-30 08:49:17 -0700
committerAlexis Beingessner <a.beingessner@gmail.com>2015-07-30 08:53:46 -0700
commitd1cf449034095725a19cba0bbc79753f2f460e69 (patch)
tree0540eb85f67da778a2661b2a962afed6285828d4
parentdbf3a63dd78f547bced8d086067d98ba0b414fd3 (diff)
downloadrust-d1cf449034095725a19cba0bbc79753f2f460e69.tar.gz
rust-d1cf449034095725a19cba0bbc79753f2f460e69.zip
Maybe ignore the explicit examples of a race condition
-rw-r--r--src/doc/tarpl/races.md20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/doc/tarpl/races.md b/src/doc/tarpl/races.md
index 240e4aca7f6..2ad62c14a80 100644
--- a/src/doc/tarpl/races.md
+++ b/src/doc/tarpl/races.md
@@ -25,7 +25,7 @@ race condition can't violate memory safety in a Rust program on
 its own. Only in conjunction with some other unsafe code can a race condition
 actually violate memory safety. For instance:
 
-```rust
+```rust,norun
 use std::thread;
 use std::sync::atomic::{AtomicUsize, Ordering};
 use std::sync::Arc;
@@ -54,6 +54,24 @@ thread::spawn(move || {
 // program execution (panicing is rarely correct) depends on order of
 // thread execution.
 println!("{}", data[idx.load(Ordering::SeqCst)]);
+```
+
+```rust,norun
+use std::thread;
+use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::Arc;
+
+let data = vec![1, 2, 3, 4];
+
+let idx = Arc::new(AtomicUsize::new(0));
+let other_idx = idx.clone();
+
+// `move` captures other_idx by-value, moving it into this thread
+thread::spawn(move || {
+    // It's ok to mutate idx because this value
+    // is an atomic, so it can't cause a Data Race.
+    other_idx.fetch_add(10, Ordering::SeqCst);
+});
 
 if idx.load(Ordering::SeqCst) < data.len() {
     unsafe {