Skip to content

Commit c60e818

Browse files
committed
---
yaml --- r: 116371 b: refs/heads/snap-stage3 c: c3825cb h: refs/heads/master i: 116369: 1c0ec48 116367: 808c73c v: v3
1 parent 38fff6b commit c60e818

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 0033a8b269aebe9d88e5e4158ef2f0cdd630e92f
4+
refs/heads/snap-stage3: c3825cbb9dfd5605c507055c40e769a5f6800bab
55
refs/heads/try: 009d898a9422ac04c1aa60c0e9aff3abc5fa4672
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/doc/intro.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ Typically, tasks do not share memory but instead communicate amongst each other
198198

199199
```
200200
fn main() {
201-
let numbers = ~[1,2,3];
201+
let numbers = vec![1,2,3];
202202
203203
let (tx, rx) = channel();
204204
tx.send(numbers);
205205
206206
spawn(proc() {
207207
let numbers = rx.recv();
208-
println!("{}", numbers[0]);
208+
println!("{}", *numbers.get(0));
209209
})
210210
}
211211
```
@@ -237,26 +237,26 @@ try to modify the previous example to continue using the variable `numbers`:
237237

238238
```ignore
239239
fn main() {
240-
let numbers = ~[1,2,3];
240+
let numbers = vec![1,2,3];
241241
242242
let (tx, rx) = channel();
243243
tx.send(numbers);
244244
245245
spawn(proc() {
246246
let numbers = rx.recv();
247-
println!("{}", numbers[0]);
247+
println!("{}", numbers.get(0));
248248
});
249249
250250
// Try to print a number from the original task
251-
println!("{}", numbers[0]);
251+
println!("{}", *numbers.get(0));
252252
}
253253
```
254254

255255
This will result an error indicating that the value is no longer in scope:
256256

257257
```notrust
258258
concurrency.rs:12:20: 12:27 error: use of moved value: 'numbers'
259-
concurrency.rs:12 println!("{}", numbers[0]);
259+
concurrency.rs:12 println!("{}", numbers.get(0));
260260
^~~~~~~
261261
```
262262

@@ -267,7 +267,7 @@ Let's see an example that uses the `clone` method to create copies of the data:
267267

268268
```
269269
fn main() {
270-
let numbers = ~[1,2,3];
270+
let numbers = vec![1,2,3];
271271
272272
for num in range(0, 3) {
273273
let (tx, rx) = channel();
@@ -276,7 +276,7 @@ fn main() {
276276
277277
spawn(proc() {
278278
let numbers = rx.recv();
279-
println!("{:d}", numbers[num as uint]);
279+
println!("{:d}", *numbers.get(num as uint));
280280
})
281281
}
282282
}
@@ -301,7 +301,7 @@ extern crate sync;
301301
use sync::Arc;
302302
303303
fn main() {
304-
let numbers = ~[1,2,3];
304+
let numbers = vec![1,2,3];
305305
let numbers = Arc::new(numbers);
306306
307307
for num in range(0, 3) {
@@ -310,7 +310,7 @@ fn main() {
310310
311311
spawn(proc() {
312312
let numbers = rx.recv();
313-
println!("{:d}", numbers[num as uint]);
313+
println!("{:d}", *numbers.get(num as uint));
314314
})
315315
}
316316
}
@@ -348,7 +348,7 @@ extern crate sync;
348348
use sync::{Arc, Mutex};
349349
350350
fn main() {
351-
let numbers = ~[1,2,3];
351+
let numbers = vec![1,2,3];
352352
let numbers_lock = Arc::new(Mutex::new(numbers));
353353
354354
for num in range(0, 3) {
@@ -360,9 +360,13 @@ fn main() {
360360
361361
// Take the lock, along with exclusive access to the underlying array
362362
let mut numbers = numbers_lock.lock();
363-
numbers[num as uint] += 1;
364363
365-
println!("{}", numbers[num as uint]);
364+
// This is ugly for now, but will be replaced by
365+
// `numbers[num as uint] += 1` in the near future.
366+
// See: https://github.com/mozilla/rust/issues/6515
367+
*numbers.get_mut(num as uint) = *numbers.get_mut(num as uint) + 1;
368+
369+
println!("{}", *numbers.get(num as uint));
366370
367371
// When `numbers` goes out of scope the lock is dropped
368372
})

0 commit comments

Comments
 (0)