Skip to content

Commit fad27d5

Browse files
committed
---
yaml --- r: 152163 b: refs/heads/try2 c: c3825cb h: refs/heads/master i: 152161: 318aead 152159: b194aa9 v: v3
1 parent 7a85a47 commit fad27d5

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 0033a8b269aebe9d88e5e4158ef2f0cdd630e92f
8+
refs/heads/try2: c3825cbb9dfd5605c507055c40e769a5f6800bab
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)