Skip to content

Commit 80209cf

Browse files
author
Olivier Saut
committed
---
yaml --- r: 60530 b: refs/heads/auto c: 3f232bc h: refs/heads/master v: v3
1 parent 528c4ba commit 80209cf

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
@@ -14,6 +14,6 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1414
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1515
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1616
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
17-
refs/heads/auto: a9c7d3f7757ee67fd5d068b0ebfb5a95d8e4d2cc
17+
refs/heads/auto: 3f232bc4a01d102599de0565ff769acdc06bac53
1818
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1919
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c

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