Remove shared_arc (unused) and fix trivial-message

This commit is contained in:
Eric Holk 2012-07-25 14:33:18 -07:00
parent 2d15b6ef42
commit 531ea695f6
2 changed files with 2 additions and 65 deletions
src
libcore
test/run-pass

@ -3,10 +3,9 @@
* share immutable data between tasks.
*/
import comm::{port, chan, methods};
import sys::methods;
export arc, get, clone, shared_arc, get_arc;
export arc, get, clone;
export exclusive, methods;
@ -122,49 +121,6 @@ impl methods<T: send> for exclusive<T> {
}
}
// Convenience code for sharing arcs between tasks
type get_chan<T: const send> = chan<chan<arc<T>>>;
// (terminate, get)
type shared_arc<T: const send> = (shared_arc_res, get_chan<T>);
class shared_arc_res {
let c: comm::chan<()>;
new(c: comm::chan<()>) { self.c = c; }
drop { self.c.send(()); }
}
fn shared_arc<T: send const>(-data: T) -> shared_arc<T> {
let a = arc::arc(data);
let p = port();
let c = chan(p);
do task::spawn() |move a| {
let mut live = true;
let terminate = port();
let get = port();
c.send((chan(terminate), chan(get)));
while live {
alt comm::select2(terminate, get) {
either::left(()) { live = false; }
either::right(cc) {
comm::send(cc, arc::clone(&a));
}
}
}
};
let (terminate, get) = p.recv();
(shared_arc_res(terminate), get)
}
fn get_arc<T: send const>(c: get_chan<T>) -> arc::arc<T> {
let p = port();
c.send(chan(p));
p.recv()
}
#[cfg(test)]
mod tests {
import comm::*;
@ -196,25 +152,6 @@ mod tests {
log(info, arc_v);
}
#[test]
fn auto_share_arc() {
let v = ~[1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let (_res, arc_c) = shared_arc(v);
let p = port();
let c = chan(p);
do task::spawn() {
let arc_v = get_arc(arc_c);
let v = *get(&arc_v);
assert v[2] == 3;
c.send(());
};
assert p.recv() == ();
}
#[test]
#[ignore] // this can probably infinite loop too.
fn exclusive_arc() {

@ -1,4 +1,4 @@
import pipes::{port, chan}
import pipes::{port, chan};
/*
This is about the simplest program that can successfully send a