1
- // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
1
+ // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2
2
// file at the top-level directory of this distribution and at
3
3
// http://rust-lang.org/COPYRIGHT.
4
4
//
8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- /*!
11
+ /**
12
12
* Concurrency-enabled mechanisms for sharing mutable and/or immutable state
13
13
* 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
- * ~~~
38
14
*/
39
15
40
16
use sync;
@@ -45,7 +21,7 @@ use core::unstable::sync::UnsafeAtomicRcBox;
45
21
use core:: ptr;
46
22
use core:: task;
47
23
48
- /// As sync::condvar, a mechanism for unlock-and-descheduling and signaling .
24
+ /// As sync::condvar, a mechanism for unlock-and-descheduling and signalling .
49
25
pub struct Condvar < ' self > {
50
26
is_mutex : bool ,
51
27
failed : & ' self mut bool ,
@@ -117,14 +93,9 @@ pub fn ARC<T:Const + Owned>(data: T) -> ARC<T> {
117
93
* wrapper.
118
94
*/
119
95
pub fn get < ' a , T : Const + Owned > ( rc : & ' a ARC < T > ) -> & ' a T {
120
- rc. get ( )
96
+ unsafe { & * rc. x . get_immut ( ) }
121
97
}
122
98
123
- impl < T : Const +Owned > ARC < T > {
124
- pub fn get < ' a > ( & ' a self ) -> & ' a T {
125
- unsafe { & * self . x . get_immut ( ) }
126
- }
127
- }
128
99
/**
129
100
* Duplicate an atomically reference counted wrapper.
130
101
*
@@ -537,7 +508,6 @@ mod tests {
537
508
c. send ( arc:: clone ( & arc_v) ) ;
538
509
539
510
assert_eq ! ( ( * arc:: get( & arc_v) ) [ 2 ] , 3 ) ;
540
- assert_eq ! ( arc_v. get( ) [ 4 ] , 5 ) ;
541
511
542
512
info ! ( arc_v) ;
543
513
}
0 commit comments