Skip to content

Commit 70f7571

Browse files
committed
---
yaml --- r: 196585 b: refs/heads/auto c: 6efb835 h: refs/heads/master i: 196583: dbfd9ef v: v3
1 parent 66a6031 commit 70f7571

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3239
-2338
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1010
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1111
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1212
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
13-
refs/heads/auto: 3b9847e886d5c92b75569e49de06a6fb7490bcb4
13+
refs/heads/auto: 6efb8352e8b066d23f6c67ffcf8ab6e60642fe2e
1414
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1515
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1616
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/intro.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -457,30 +457,25 @@ a problem. That’s what it means by ‘cannot move out of captured outer
457457
variable’: our `thread::scoped` closure wants to take ownership, and it can’t,
458458
because the closure for `map` won’t let it.
459459
460-
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
461-
*Arc* stands for "atomically reference counted". In other words, an Arc will
462-
keep track of the number of references to something, and not free the
463-
associated resource until the count is zero. The *atomic* portion refers to an
464-
Arc's usage of concurrency primitives to atomically update the count, making it
465-
safe across threads. If we use an Arc, we can have our three references. But,
466-
an Arc does not allow mutable borrows of the data it holds, and we want to
467-
modify what we're sharing. In this case, we can use a `Mutex<T>` inside of our
468-
Arc. A Mutex will synchronize our accesses, so that we can ensure that our
469-
mutation doesn't cause a data race.
470-
471-
Here's what using an Arc with a Mutex looks like:
460+
What to do here? Rust has a type that helps us: `Mutex<T>`. Because the threads
461+
are scoped, it is possible to use an _immutable_ reference to `numbers` inside
462+
of the closure. However, Rust prevents us from having multiple _mutable_
463+
references to the same object, so we need a `Mutex` to be able to modify what
464+
we're sharing. A Mutex will synchronize our accesses, so that we can ensure
465+
that our mutation doesn't cause a data race.
466+
467+
Here's what using a Mutex looks like:
472468
473469
```{rust}
474470
use std::thread;
475-
use std::sync::{Arc,Mutex};
471+
use std::sync::Mutex;
476472
477473
fn main() {
478-
let numbers = Arc::new(Mutex::new(vec![1, 2, 3]));
474+
let numbers = &Mutex::new(vec![1, 2, 3]);
479475
480476
let guards: Vec<_> = (0..3).map(|i| {
481-
let number = numbers.clone();
482477
thread::scoped(move || {
483-
let mut array = number.lock().unwrap();
478+
let mut array = numbers.lock().unwrap();
484479
array[i] += 1;
485480
println!("numbers[{}] is {}", i, array[i]);
486481
})
@@ -489,12 +484,9 @@ fn main() {
489484
```
490485
491486
We first have to `use` the appropriate library, and then we wrap our vector in
492-
an Arc with the call to `Arc::new()`. Inside of the loop, we make a new
493-
reference to the Arc with the `clone()` method. This will increment the
494-
reference count. When each new `numbers` variable binding goes out of scope, it
495-
will decrement the count. The `lock()` call will return us a reference to the
496-
value inside the Mutex, and block any other calls to `lock()` until said
497-
reference goes out of scope.
487+
a `Mutex` with the call to `Mutex::new()`. Inside of the loop, the `lock()`
488+
call will return us a reference to the value inside the Mutex, and block any
489+
other calls to `lock()` until said reference goes out of scope.
498490
499491
We can compile and run this program without error, and in fact, see the
500492
non-deterministic aspect:

branches/auto/src/doc/trpl/benchmark-tests.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn add_two(a: i32) -> i32 {
1313
}
1414
1515
#[cfg(test)]
16-
mod tests {
16+
mod test {
1717
use super::*;
1818
use test::Bencher;
1919

branches/auto/src/doc/trpl/hello-cargo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
% Hello, Cargo!
22

33
[Cargo](http://crates.io) is a tool that Rustaceans use to help manage their
4-
Rust projects. Cargo is currently in an alpha state, just like Rust, and so it
4+
Rust projects. Cargo is currently in a pre-1.0 state, just like Rust, and so it
55
is still a work in progress. However, it is already good enough to use for many
66
Rust projects, and so it is assumed that Rust projects will use Cargo from the
77
beginning.

branches/auto/src/doc/trpl/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pub fn add_two(a: i32) -> i32 {
382382
}
383383
384384
#[cfg(test)]
385-
mod tests {
385+
mod test {
386386
use super::*;
387387
388388
#[test]

0 commit comments

Comments
 (0)