@@ -50,7 +50,7 @@ concurrency at this writing:
50
50
* [ ` std::pipes ` ] - The underlying messaging infrastructure,
51
51
* [ ` extra::comm ` ] - Additional messaging types based on ` std::pipes ` ,
52
52
* [ ` extra::sync ` ] - More exotic synchronization tools, including locks,
53
- * [ ` extra::arc ` ] - The ARC (atomically reference counted) type,
53
+ * [ ` extra::arc ` ] - The Arc (atomically reference counted) type,
54
54
for safely sharing immutable data,
55
55
* [ ` extra::future ` ] - A type representing values that may be computed concurrently and retrieved at a later time.
56
56
@@ -334,24 +334,24 @@ fn main() {
334
334
}
335
335
~~~
336
336
337
- ## Sharing immutable data without copy: ARC
337
+ ## Sharing immutable data without copy: Arc
338
338
339
339
To share immutable data between tasks, a first approach would be to only use pipes as we have seen
340
340
previously. A copy of the data to share would then be made for each task. In some cases, this would
341
341
add up to a significant amount of wasted memory and would require copying the same data more than
342
342
necessary.
343
343
344
- To tackle this issue, one can use an Atomically Reference Counted wrapper (` ARC ` ) as implemented in
345
- the ` extra ` library of Rust. With an ARC , the data will no longer be copied for each task. The ARC
344
+ To tackle this issue, one can use an Atomically Reference Counted wrapper (` Arc ` ) as implemented in
345
+ the ` extra ` library of Rust. With an Arc , the data will no longer be copied for each task. The Arc
346
346
acts as a reference to the shared data and only this reference is shared and cloned.
347
347
348
- Here is a small example showing how to use ARCs . We wish to run concurrently several computations on
348
+ Here is a small example showing how to use Arcs . We wish to run concurrently several computations on
349
349
a single large vector of floats. Each task needs the full vector to perform its duty.
350
350
~~~
351
351
# use std::vec;
352
352
# use std::uint;
353
353
# use std::rand;
354
- use extra::arc::ARC ;
354
+ use extra::arc::Arc ;
355
355
356
356
fn pnorm(nums: &~[float], p: uint) -> float {
357
357
nums.iter().fold(0.0, |a,b| a+(*b).pow(&(p as float)) ).pow(&(1f / (p as float)))
@@ -361,14 +361,14 @@ fn main() {
361
361
let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
362
362
println(fmt!("Inf-norm = %?", *numbers.iter().max().unwrap()));
363
363
364
- let numbers_arc = ARC (numbers);
364
+ let numbers_arc = Arc::new (numbers);
365
365
366
366
for uint::range(1,10) |num| {
367
367
let (port, chan) = stream();
368
368
chan.send(numbers_arc.clone());
369
369
370
370
do spawn {
371
- let local_arc : ARC <~[float]> = port.recv();
371
+ let local_arc : Arc <~[float]> = port.recv();
372
372
let task_numbers = local_arc.get();
373
373
println(fmt!("%u-norm = %?", num, pnorm(task_numbers, num)));
374
374
}
@@ -377,42 +377,42 @@ fn main() {
377
377
~~~
378
378
379
379
The function ` pnorm ` performs a simple computation on the vector (it computes the sum of its items
380
- at the power given as argument and takes the inverse power of this value). The ARC on the vector is
380
+ at the power given as argument and takes the inverse power of this value). The Arc on the vector is
381
381
created by the line
382
382
~~~
383
- # use extra::arc::ARC ;
383
+ # use extra::arc::Arc ;
384
384
# use std::vec;
385
385
# use std::rand;
386
386
# let numbers = vec::from_fn(1000000, |_| rand::random::<float>());
387
- let numbers_arc=ARC (numbers);
387
+ let numbers_arc=Arc::new (numbers);
388
388
~~~
389
389
and a clone of it is sent to each task
390
390
~~~
391
- # use extra::arc::ARC ;
391
+ # use extra::arc::Arc ;
392
392
# use std::vec;
393
393
# use std::rand;
394
394
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
395
- # let numbers_arc = ARC (numbers);
395
+ # let numbers_arc = Arc::new (numbers);
396
396
# let (port, chan) = stream();
397
397
chan.send(numbers_arc.clone());
398
398
~~~
399
399
copying only the wrapper and not its contents.
400
400
401
401
Each task recovers the underlying data by
402
402
~~~
403
- # use extra::arc::ARC ;
403
+ # use extra::arc::Arc ;
404
404
# use std::vec;
405
405
# use std::rand;
406
406
# let numbers=vec::from_fn(1000000, |_| rand::random::<float>());
407
- # let numbers_arc=ARC (numbers);
407
+ # let numbers_arc=Arc::new (numbers);
408
408
# let (port, chan) = stream();
409
409
# chan.send(numbers_arc.clone());
410
- # let local_arc : ARC <~[float]> = port.recv();
410
+ # let local_arc : Arc <~[float]> = port.recv();
411
411
let task_numbers = local_arc.get();
412
412
~~~
413
413
and can use it as if it were local.
414
414
415
- The ` arc ` module also implements ARCs around mutable data that are not covered here.
415
+ The ` arc ` module also implements Arcs around mutable data that are not covered here.
416
416
417
417
# Handling task failure
418
418
0 commit comments