From e1389530cf5dca112f5d282acfa7f08a08e114bc Mon Sep 17 00:00:00 2001 From: Neil Pankey Date: Sat, 18 Oct 2014 16:15:38 -0700 Subject: [PATCH 1/2] [Docs] intro typo --- src/doc/intro.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/doc/intro.md b/src/doc/intro.md index b45610faebc41..1eb2d6f64e74b 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -442,10 +442,10 @@ It gives us this error: ``` It mentions that "numbers moved into closure environment". Because we referred -to `numbers` inside of our `proc`, and we create ten `proc`s, we would have ten -references. Rust detects this and gives us the error: we claim that `numbers` -has ownership, but our code tries to make ten owners. This may cause a safety -problem, so Rust disallows it. +to `numbers` inside of our `proc`, and we create three `proc`s, we would have +three references. Rust detects this and gives us the error: we claim that +`numbers` has ownership, but our code tries to make ten owners. This may cause +a safety problem, so Rust disallows it. What to do here? Rust has two types that helps us: `Arc` and `Mutex`. "Arc" stands for "atomically reference counted." In other words, an Arc will From 66939dfe645a2eaf2ba9a2750122836a37271db1 Mon Sep 17 00:00:00 2001 From: Neil Pankey Date: Sat, 18 Oct 2014 17:40:32 -0700 Subject: [PATCH 2/2] [Docs] more intro typos --- src/doc/intro.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/doc/intro.md b/src/doc/intro.md index 1eb2d6f64e74b..21ec551eb3024 100644 --- a/src/doc/intro.md +++ b/src/doc/intro.md @@ -444,19 +444,19 @@ It gives us this error: It mentions that "numbers moved into closure environment". Because we referred to `numbers` inside of our `proc`, and we create three `proc`s, we would have three references. Rust detects this and gives us the error: we claim that -`numbers` has ownership, but our code tries to make ten owners. This may cause -a safety problem, so Rust disallows it. +`numbers` has ownership, but our code tries to make three owners. This may +cause a safety problem, so Rust disallows it. What to do here? Rust has two types that helps us: `Arc` and `Mutex`. "Arc" stands for "atomically reference counted." In other words, an Arc will keep track of the number of references to something, and not free the associated resource until the count is zero. The 'atomic' portion refers to an Arc's usage of concurrency primitives to atomically update the count, making it -safe across threads. If we use an Arc, we can have our ten references. But, an -Arc does not allow mutable borrows of the data it holds, and we want to modify -what we're sharing. In this case, we can use a `Mutex` inside of our Arc. A -Mutex will synchronize our accesses, so that we can ensure that our mutation -doesn't cause a data race. +safe across threads. If we use an Arc, we can have our three references. But, +an Arc does not allow mutable borrows of the data it holds, and we want to +modify what we're sharing. In this case, we can use a `Mutex` inside of our +Arc. A Mutex will synchronize our accesses, so that we can ensure that our +mutation doesn't cause a data race. Here's what using an Arc with a Mutex looks like: