Skip to content

Commit b2e5773

Browse files
committed
auto merge of #18145 : neilpa/rust/master, r=steveklabnik
Noticed a type while reading through the intro
2 parents 6353465 + 66939df commit b2e5773

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/doc/intro.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,21 @@ It gives us this error:
442442
```
443443

444444
It mentions that "numbers moved into closure environment". Because we referred
445-
to `numbers` inside of our `proc`, and we create ten `proc`s, we would have ten
446-
references. Rust detects this and gives us the error: we claim that `numbers`
447-
has ownership, but our code tries to make ten owners. This may cause a safety
448-
problem, so Rust disallows it.
445+
to `numbers` inside of our `proc`, and we create three `proc`s, we would have
446+
three references. Rust detects this and gives us the error: we claim that
447+
`numbers` has ownership, but our code tries to make three owners. This may
448+
cause a safety problem, so Rust disallows it.
449449

450450
What to do here? Rust has two types that helps us: `Arc<T>` and `Mutex<T>`.
451451
"Arc" stands for "atomically reference counted." In other words, an Arc will
452452
keep track of the number of references to something, and not free the
453453
associated resource until the count is zero. The 'atomic' portion refers to an
454454
Arc's usage of concurrency primitives to atomically update the count, making it
455-
safe across threads. If we use an Arc, we can have our ten references. But, an
456-
Arc does not allow mutable borrows of the data it holds, and we want to modify
457-
what we're sharing. In this case, we can use a `Mutex<T>` inside of our Arc. A
458-
Mutex will synchronize our accesses, so that we can ensure that our mutation
459-
doesn't cause a data race.
455+
safe across threads. If we use an Arc, we can have our three references. But,
456+
an Arc does not allow mutable borrows of the data it holds, and we want to
457+
modify what we're sharing. In this case, we can use a `Mutex<T>` inside of our
458+
Arc. A Mutex will synchronize our accesses, so that we can ensure that our
459+
mutation doesn't cause a data race.
460460

461461
Here's what using an Arc with a Mutex looks like:
462462

0 commit comments

Comments
 (0)