|
3 | 3 | * share immutable data between tasks.
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -import comm::{port, chan, methods}; |
7 | 6 | import sys::methods;
|
8 | 7 |
|
9 |
| -export arc, get, clone, shared_arc, get_arc; |
| 8 | +export arc, get, clone; |
10 | 9 |
|
11 | 10 | export exclusive, methods;
|
12 | 11 |
|
@@ -122,49 +121,6 @@ impl methods<T: send> for exclusive<T> {
|
122 | 121 | }
|
123 | 122 | }
|
124 | 123 |
|
125 |
| -// Convenience code for sharing arcs between tasks |
126 |
| - |
127 |
| -type get_chan<T: const send> = chan<chan<arc<T>>>; |
128 |
| - |
129 |
| -// (terminate, get) |
130 |
| -type shared_arc<T: const send> = (shared_arc_res, get_chan<T>); |
131 |
| - |
132 |
| -class shared_arc_res { |
133 |
| - let c: comm::chan<()>; |
134 |
| - new(c: comm::chan<()>) { self.c = c; } |
135 |
| - drop { self.c.send(()); } |
136 |
| -} |
137 |
| - |
138 |
| -fn shared_arc<T: send const>(-data: T) -> shared_arc<T> { |
139 |
| - let a = arc::arc(data); |
140 |
| - let p = port(); |
141 |
| - let c = chan(p); |
142 |
| - do task::spawn() |move a| { |
143 |
| - let mut live = true; |
144 |
| - let terminate = port(); |
145 |
| - let get = port(); |
146 |
| - |
147 |
| - c.send((chan(terminate), chan(get))); |
148 |
| - |
149 |
| - while live { |
150 |
| - alt comm::select2(terminate, get) { |
151 |
| - either::left(()) { live = false; } |
152 |
| - either::right(cc) { |
153 |
| - comm::send(cc, arc::clone(&a)); |
154 |
| - } |
155 |
| - } |
156 |
| - } |
157 |
| - }; |
158 |
| - let (terminate, get) = p.recv(); |
159 |
| - (shared_arc_res(terminate), get) |
160 |
| -} |
161 |
| - |
162 |
| -fn get_arc<T: send const>(c: get_chan<T>) -> arc::arc<T> { |
163 |
| - let p = port(); |
164 |
| - c.send(chan(p)); |
165 |
| - p.recv() |
166 |
| -} |
167 |
| - |
168 | 124 | #[cfg(test)]
|
169 | 125 | mod tests {
|
170 | 126 | import comm::*;
|
@@ -196,25 +152,6 @@ mod tests {
|
196 | 152 | log(info, arc_v);
|
197 | 153 | }
|
198 | 154 |
|
199 |
| - #[test] |
200 |
| - fn auto_share_arc() { |
201 |
| - let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; |
202 |
| - let (_res, arc_c) = shared_arc(v); |
203 |
| - |
204 |
| - let p = port(); |
205 |
| - let c = chan(p); |
206 |
| - |
207 |
| - do task::spawn() { |
208 |
| - let arc_v = get_arc(arc_c); |
209 |
| - let v = *get(&arc_v); |
210 |
| - assert v[2] == 3; |
211 |
| - |
212 |
| - c.send(()); |
213 |
| - }; |
214 |
| - |
215 |
| - assert p.recv() == (); |
216 |
| - } |
217 |
| - |
218 | 155 | #[test]
|
219 | 156 | #[ignore] // this can probably infinite loop too.
|
220 | 157 | fn exclusive_arc() {
|
|
0 commit comments