Skip to content

Commit a655b93

Browse files
author
Olivier Saut
committed
---
yaml --- r: 62527 b: refs/heads/snap-stage3 c: 3f232bc h: refs/heads/master i: 62525: 6ef26a6 62523: 191c46a 62519: bb7fba4 62511: b9afd50 62495: fabdb0e 62463: e2ae320 v: v3
1 parent 8abb29b commit a655b93

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
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: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a9c7d3f7757ee67fd5d068b0ebfb5a95d8e4d2cc
4+
refs/heads/snap-stage3: 3f232bc4a01d102599de0565ff769acdc06bac53
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/arc.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,33 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
/**
11+
/*!
1212
* Concurrency-enabled mechanisms for sharing mutable and/or immutable state
1313
* between tasks.
14+
*
15+
* # Example
16+
*
17+
* In this example, a large vector of floats is shared between several tasks.
18+
* With simple pipes, without ARC, a copy would have to be made for each task.
19+
*
20+
* ~~~
21+
* extern mod std;
22+
* use std::arc;
23+
* let numbers=vec::from_fn(100, |ind| (ind as float)*rand::random());
24+
* let shared_numbers=arc::ARC(numbers);
25+
*
26+
* for 10.times {
27+
* let (port, chan) = stream();
28+
* chan.send(shared_numbers.clone());
29+
*
30+
* do spawn {
31+
* let shared_numbers=port.recv();
32+
* let local_numbers=shared_numbers.get();
33+
*
34+
* // Work with the local numbers
35+
* }
36+
* }
37+
* ~~~
1438
*/
1539

1640
use sync;
@@ -93,9 +117,14 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
93117
* wrapper.
94118
*/
95119
pub fn get<'a, T:Const + Owned>(rc: &'a ARC<T>) -> &'a T {
96-
unsafe { &*rc.x.get_immut() }
120+
rc.get()
97121
}
98122

123+
impl<T:Const+Owned> ARC<T> {
124+
pub fn get<'a>(&'a self) -> &'a T {
125+
unsafe { &*self.x.get_immut() }
126+
}
127+
}
99128
/**
100129
* Duplicate an atomically reference counted wrapper.
101130
*
@@ -508,6 +537,7 @@ mod tests {
508537
c.send(arc::clone(&arc_v));
509538

510539
assert_eq!((*arc::get(&arc_v))[2], 3);
540+
assert_eq!(arc_v.get()[4], 5);
511541

512542
info!(arc_v);
513543
}

0 commit comments

Comments
 (0)