auto merge of #12815 : alexcrichton/rust/chan-rename, r=brson
* Chan<T> => Sender<T> * Port<T> => Receiver<T> * Chan::new() => channel() * constructor returns (Sender, Receiver) instead of (Receiver, Sender) * local variables named `port` renamed to `rx` * local variables named `chan` renamed to `tx` Closes #11765
This commit is contained in:
commit
b4d324334c
117 changed files with 1735 additions and 1890 deletions
|
|
@ -10,10 +10,10 @@
|
|||
|
||||
use std::task;
|
||||
|
||||
pub fn foo<T:Send + Clone>(x: T) -> Port<T> {
|
||||
let (p, c) = Chan::new();
|
||||
pub fn foo<T:Send + Clone>(x: T) -> Receiver<T> {
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(proc() {
|
||||
c.send(x.clone());
|
||||
tx.send(x.clone());
|
||||
});
|
||||
p
|
||||
rx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ enum request {
|
|||
stop
|
||||
}
|
||||
|
||||
fn server(requests: &Port<request>, responses: &Chan<uint>) {
|
||||
fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
|
||||
let mut count = 0u;
|
||||
let mut done = false;
|
||||
while !done {
|
||||
|
|
@ -52,8 +52,8 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
|
|||
}
|
||||
|
||||
fn run(args: &[~str]) {
|
||||
let (from_child, to_parent) = Chan::new();
|
||||
let (from_parent, to_child) = Chan::new();
|
||||
let (to_parent, from_child) = channel();
|
||||
let (to_child, from_parent) = channel();
|
||||
|
||||
let size = from_str::<uint>(args[1]).unwrap();
|
||||
let workers = from_str::<uint>(args[2]).unwrap();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ enum request {
|
|||
stop
|
||||
}
|
||||
|
||||
fn server(requests: &Port<request>, responses: &Chan<uint>) {
|
||||
fn server(requests: &Receiver<request>, responses: &Sender<uint>) {
|
||||
let mut count: uint = 0;
|
||||
let mut done = false;
|
||||
while !done {
|
||||
|
|
@ -47,7 +47,7 @@ fn server(requests: &Port<request>, responses: &Chan<uint>) {
|
|||
}
|
||||
|
||||
fn run(args: &[~str]) {
|
||||
let (from_child, to_parent) = Chan::new();
|
||||
let (to_parent, from_child) = channel();
|
||||
|
||||
let size = from_str::<uint>(args[1]).unwrap();
|
||||
let workers = from_str::<uint>(args[2]).unwrap();
|
||||
|
|
@ -55,7 +55,7 @@ fn run(args: &[~str]) {
|
|||
let start = time::precise_time_s();
|
||||
let mut worker_results = ~[];
|
||||
let from_parent = if workers == 1 {
|
||||
let (from_parent, to_child) = Chan::new();
|
||||
let (to_child, from_parent) = channel();
|
||||
let mut builder = task::task();
|
||||
worker_results.push(builder.future_result());
|
||||
builder.spawn(proc() {
|
||||
|
|
@ -67,7 +67,7 @@ fn run(args: &[~str]) {
|
|||
});
|
||||
from_parent
|
||||
} else {
|
||||
let (from_parent, to_child) = Chan::new();
|
||||
let (to_child, from_parent) = channel();
|
||||
for _ in range(0u, workers) {
|
||||
let to_child = to_child.clone();
|
||||
let mut builder = task::task();
|
||||
|
|
|
|||
|
|
@ -32,25 +32,23 @@ fn ping_pong_bench(n: uint, m: uint) {
|
|||
// Create pairs of tasks that pingpong back and forth.
|
||||
fn run_pair(n: uint) {
|
||||
// Create a stream A->B
|
||||
let (pa,ca) = Chan::<()>::new();
|
||||
let (atx, arx) = channel::<()>();
|
||||
// Create a stream B->A
|
||||
let (pb,cb) = Chan::<()>::new();
|
||||
let (btx, brx) = channel::<()>();
|
||||
|
||||
spawn(proc() {
|
||||
let chan = ca;
|
||||
let port = pb;
|
||||
let (tx, rx) = (atx, brx);
|
||||
for _ in range(0, n) {
|
||||
chan.send(());
|
||||
port.recv();
|
||||
tx.send(());
|
||||
rx.recv();
|
||||
}
|
||||
});
|
||||
|
||||
spawn(proc() {
|
||||
let chan = cb;
|
||||
let port = pa;
|
||||
let (tx, rx) = (btx, arx);
|
||||
for _ in range(0, n) {
|
||||
port.recv();
|
||||
chan.send(());
|
||||
rx.recv();
|
||||
tx.send(());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ fn parfib(n: uint) -> uint {
|
|||
return 1;
|
||||
}
|
||||
|
||||
let (port,chan) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
chan.send(parfib(n-1));
|
||||
tx.send(parfib(n-1));
|
||||
});
|
||||
let m2 = parfib(n-2);
|
||||
return (port.recv() + m2);
|
||||
return (rx.recv() + m2);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -99,9 +99,9 @@ fn transform(aa: color, bb: color) -> color {
|
|||
fn creature(
|
||||
name: uint,
|
||||
color: color,
|
||||
from_rendezvous: Port<Option<CreatureInfo>>,
|
||||
to_rendezvous: Chan<CreatureInfo>,
|
||||
to_rendezvous_log: Chan<~str>
|
||||
from_rendezvous: Receiver<Option<CreatureInfo>>,
|
||||
to_rendezvous: Sender<CreatureInfo>,
|
||||
to_rendezvous_log: Sender<~str>
|
||||
) {
|
||||
let mut color = color;
|
||||
let mut creatures_met = 0;
|
||||
|
|
@ -137,13 +137,13 @@ fn creature(
|
|||
fn rendezvous(nn: uint, set: ~[color]) {
|
||||
|
||||
// these ports will allow us to hear from the creatures
|
||||
let (from_creatures, to_rendezvous) = Chan::<CreatureInfo>::new();
|
||||
let (from_creatures_log, to_rendezvous_log) = Chan::<~str>::new();
|
||||
let (to_rendezvous, from_creatures) = channel::<CreatureInfo>();
|
||||
let (to_rendezvous_log, from_creatures_log) = channel::<~str>();
|
||||
|
||||
// these channels will be passed to the creatures so they can talk to us
|
||||
|
||||
// these channels will allow us to talk to each creature by 'name'/index
|
||||
let to_creature: ~[Chan<Option<CreatureInfo>>] =
|
||||
let to_creature: ~[Sender<Option<CreatureInfo>>] =
|
||||
set.iter().enumerate().map(|(ii, col)| {
|
||||
// create each creature as a listener with a port, and
|
||||
// give us a channel to talk to each
|
||||
|
|
@ -151,7 +151,7 @@ fn rendezvous(nn: uint, set: ~[color]) {
|
|||
let col = *col;
|
||||
let to_rendezvous = to_rendezvous.clone();
|
||||
let to_rendezvous_log = to_rendezvous_log.clone();
|
||||
let (from_rendezvous, to_creature) = Chan::new();
|
||||
let (to_creature, from_rendezvous) = channel();
|
||||
task::spawn(proc() {
|
||||
creature(ii,
|
||||
col,
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ fn windows_with_carry(bb: &[u8], nn: uint, it: |window: &[u8]|) -> ~[u8] {
|
|||
}
|
||||
|
||||
fn make_sequence_processor(sz: uint,
|
||||
from_parent: &Port<~[u8]>,
|
||||
to_parent: &Chan<~str>) {
|
||||
from_parent: &Receiver<~[u8]>,
|
||||
to_parent: &Sender<~str>) {
|
||||
let mut freqs: HashMap<~[u8], uint> = HashMap::new();
|
||||
let mut carry: ~[u8] = ~[];
|
||||
let mut total: uint = 0u;
|
||||
|
|
@ -158,23 +158,23 @@ fn main() {
|
|||
|
||||
// initialize each sequence sorter
|
||||
let sizes = ~[1u,2,3,4,6,12,18];
|
||||
let mut streams = vec::from_fn(sizes.len(), |_| Some(Chan::<~str>::new()));
|
||||
let mut streams = vec::from_fn(sizes.len(), |_| Some(channel::<~str>()));
|
||||
let mut from_child = ~[];
|
||||
let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| {
|
||||
let to_child = sizes.iter().zip(streams.mut_iter()).map(|(sz, stream_ref)| {
|
||||
let sz = *sz;
|
||||
let stream = replace(stream_ref, None);
|
||||
let (from_child_, to_parent_) = stream.unwrap();
|
||||
let (to_parent_, from_child_) = stream.unwrap();
|
||||
|
||||
from_child.push(from_child_);
|
||||
|
||||
let (from_parent, to_child) = Chan::new();
|
||||
let (to_child, from_parent) = channel();
|
||||
|
||||
spawn(proc() {
|
||||
make_sequence_processor(sz, &from_parent, &to_parent_);
|
||||
});
|
||||
|
||||
to_child
|
||||
}).collect::<~[Chan<~[u8]>]>();
|
||||
}).collect::<~[Sender<~[u8]>]>();
|
||||
|
||||
|
||||
// latch stores true after we've started
|
||||
|
|
|
|||
|
|
@ -27,24 +27,24 @@ use std::task;
|
|||
use std::uint;
|
||||
|
||||
fn fib(n: int) -> int {
|
||||
fn pfib(c: &Chan<int>, n: int) {
|
||||
fn pfib(tx: &Sender<int>, n: int) {
|
||||
if n == 0 {
|
||||
c.send(0);
|
||||
tx.send(0);
|
||||
} else if n <= 2 {
|
||||
c.send(1);
|
||||
tx.send(1);
|
||||
} else {
|
||||
let (pp, cc) = Chan::new();
|
||||
let ch = cc.clone();
|
||||
task::spawn(proc() pfib(&ch, n - 1));
|
||||
let ch = cc.clone();
|
||||
task::spawn(proc() pfib(&ch, n - 2));
|
||||
c.send(pp.recv() + pp.recv());
|
||||
let (tx1, rx) = channel();
|
||||
let tx2 = tx1.clone();
|
||||
task::spawn(proc() pfib(&tx2, n - 1));
|
||||
let tx2 = tx1.clone();
|
||||
task::spawn(proc() pfib(&tx2, n - 2));
|
||||
tx.send(rx.recv() + rx.recv());
|
||||
}
|
||||
}
|
||||
|
||||
let (p, ch) = Chan::new();
|
||||
let _t = task::spawn(proc() pfib(&ch, n) );
|
||||
p.recv()
|
||||
let (tx, rx) = channel();
|
||||
spawn(proc() pfib(&tx, n) );
|
||||
rx.recv()
|
||||
}
|
||||
|
||||
struct Config {
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) {
|
|||
// tasks. To do that, we give to each tasks a wait_chan that we
|
||||
// drop at the end of the work. At the end of this function, we
|
||||
// wait until the channel hang up.
|
||||
let (wait_port, wait_chan) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let len = out.read(|out| out.len());
|
||||
let chunk = len / 100 + 1;
|
||||
for chk in count(0, chunk) {
|
||||
if chk >= len {break;}
|
||||
let w = wait_chan.clone();
|
||||
let tx = tx.clone();
|
||||
let v = v.clone();
|
||||
let out = out.clone();
|
||||
spawn(proc() {
|
||||
|
|
@ -49,13 +49,13 @@ fn mult(v: RWArc<~[f64]>, out: RWArc<~[f64]>, f: fn(&~[f64], uint) -> f64) {
|
|||
let val = v.read(|v| f(v, i));
|
||||
out.write(|out| out[i] = val);
|
||||
}
|
||||
drop(w)
|
||||
drop(tx)
|
||||
});
|
||||
}
|
||||
|
||||
// wait until the channel hang up (every task finished)
|
||||
drop(wait_chan);
|
||||
for () in wait_port.iter() {}
|
||||
drop(tx);
|
||||
for () in rx.iter() {}
|
||||
}
|
||||
|
||||
fn mult_Av_impl(v: &~[f64], i: uint) -> f64 {
|
||||
|
|
|
|||
|
|
@ -13,30 +13,27 @@
|
|||
use std::os;
|
||||
|
||||
fn start(n_tasks: int, token: int) {
|
||||
let (p, ch1) = Chan::new();
|
||||
let mut p = p;
|
||||
let ch1 = ch1;
|
||||
ch1.send(token);
|
||||
let (tx, mut rx) = channel();
|
||||
tx.send(token);
|
||||
// XXX could not get this to work with a range closure
|
||||
let mut i = 2;
|
||||
while i <= n_tasks {
|
||||
let (next_p, ch) = Chan::new();
|
||||
let (tx, next_rx) = channel();
|
||||
let imm_i = i;
|
||||
let imm_p = p;
|
||||
let imm_rx = rx;
|
||||
spawn(proc() {
|
||||
roundtrip(imm_i, n_tasks, &imm_p, &ch);
|
||||
roundtrip(imm_i, n_tasks, &imm_rx, &tx);
|
||||
});
|
||||
p = next_p;
|
||||
rx = next_rx;
|
||||
i += 1;
|
||||
}
|
||||
let imm_p = p;
|
||||
let imm_ch = ch1;
|
||||
let imm_rx = rx;
|
||||
spawn(proc() {
|
||||
roundtrip(1, n_tasks, &imm_p, &imm_ch);
|
||||
roundtrip(1, n_tasks, &imm_rx, &tx);
|
||||
});
|
||||
}
|
||||
|
||||
fn roundtrip(id: int, n_tasks: int, p: &Port<int>, ch: &Chan<int>) {
|
||||
fn roundtrip(id: int, n_tasks: int, p: &Receiver<int>, ch: &Sender<int>) {
|
||||
loop {
|
||||
match p.recv() {
|
||||
1 => {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ use std::os;
|
|||
use std::task;
|
||||
use std::uint;
|
||||
|
||||
fn child_generation(gens_left: uint, c: comm::Chan<()>) {
|
||||
fn child_generation(gens_left: uint, tx: comm::Sender<()>) {
|
||||
// This used to be O(n^2) in the number of generations that ever existed.
|
||||
// With this code, only as many generations are alive at a time as tasks
|
||||
// alive at a time,
|
||||
|
|
@ -31,9 +31,9 @@ fn child_generation(gens_left: uint, c: comm::Chan<()>) {
|
|||
task::deschedule(); // shake things up a bit
|
||||
}
|
||||
if gens_left > 0 {
|
||||
child_generation(gens_left - 1, c); // recurse
|
||||
child_generation(gens_left - 1, tx); // recurse
|
||||
} else {
|
||||
c.send(())
|
||||
tx.send(())
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -48,9 +48,9 @@ fn main() {
|
|||
args.clone()
|
||||
};
|
||||
|
||||
let (p,c) = Chan::new();
|
||||
child_generation(from_str::<uint>(args[1]).unwrap(), c);
|
||||
if p.recv_opt().is_none() {
|
||||
let (tx, rx) = channel();
|
||||
child_generation(from_str::<uint>(args[1]).unwrap(), tx);
|
||||
if rx.recv_opt().is_none() {
|
||||
fail!("it happened when we slumbered");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,24 +17,24 @@ use std::task;
|
|||
use std::uint;
|
||||
use std::vec;
|
||||
|
||||
fn calc(children: uint, parent_wait_chan: &Chan<Chan<Chan<int>>>) {
|
||||
fn calc(children: uint, parent_wait_chan: &Sender<Sender<Sender<int>>>) {
|
||||
|
||||
let wait_ports: ~[Port<Chan<Chan<int>>>] = vec::from_fn(children, |_| {
|
||||
let (wait_port, wait_chan) = stream::<Chan<Chan<int>>>();
|
||||
let wait_ports: ~[Receiver<Sender<Sender<int>>>] = vec::from_fn(children, |_| {
|
||||
let (wait_port, wait_chan) = stream::<Sender<Sender<int>>>();
|
||||
task::spawn(proc() {
|
||||
calc(children / 2, &wait_chan);
|
||||
});
|
||||
wait_port
|
||||
});
|
||||
|
||||
let child_start_chans: ~[Chan<Chan<int>>] =
|
||||
let child_start_chans: ~[Sender<Sender<int>>] =
|
||||
wait_ports.move_iter().map(|port| port.recv()).collect();
|
||||
|
||||
let (start_port, start_chan) = stream::<Chan<int>>();
|
||||
let (start_port, start_chan) = stream::<Sender<int>>();
|
||||
parent_wait_chan.send(start_chan);
|
||||
let parent_result_chan: Chan<int> = start_port.recv();
|
||||
let parent_result_chan: Sender<int> = start_port.recv();
|
||||
|
||||
let child_sum_ports: ~[Port<int>] =
|
||||
let child_sum_ports: ~[Receiver<int>] =
|
||||
child_start_chans.move_iter().map(|child_start_chan| {
|
||||
let (child_sum_port, child_sum_chan) = stream::<int>();
|
||||
child_start_chan.send(child_sum_chan);
|
||||
|
|
|
|||
|
|
@ -9,9 +9,9 @@
|
|||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
let x = Some(p);
|
||||
c.send(false);
|
||||
let (tx, rx) = channel();
|
||||
let x = Some(rx);
|
||||
tx.send(false);
|
||||
match x {
|
||||
Some(z) if z.recv() => { fail!() }, //~ ERROR cannot bind by-move into a pattern guard
|
||||
Some(z) => { assert!(!z.recv()); },
|
||||
|
|
|
|||
|
|
@ -65,4 +65,4 @@ fn assign3<'a>(x: &'a mut Own<int>) {
|
|||
**x = 3;
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
pub fn main() {}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
// to use capabilities granted by builtin kinds as supertraits.
|
||||
|
||||
trait Foo : Freeze {
|
||||
fn foo(self, mut chan: Chan<Self>) {
|
||||
fn foo(self, mut chan: Sender<Self>) {
|
||||
chan.send(self); //~ ERROR does not fulfill `Send`
|
||||
}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ trait Foo : Freeze {
|
|||
impl <T: Freeze> Foo for T { }
|
||||
|
||||
fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
1193182.foo(c);
|
||||
assert!(p.recv() == 1193182);
|
||||
let (tx, rx) = channel();
|
||||
1193182.foo(tx);
|
||||
assert!(rx.recv() == 1193182);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
fn test<T: Freeze>() {}
|
||||
|
||||
fn main() {
|
||||
test::<Chan<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
test::<Port<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
test::<Chan<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
test::<Sender<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
test::<Receiver<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
test::<Sender<int>>(); //~ ERROR: does not fulfill `Freeze`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,4 +21,4 @@ extern {
|
|||
fn this_is_actually_ok(a: uint);
|
||||
fn and_so_is_this(_: uint);
|
||||
}
|
||||
fn main() {}
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -27,6 +27,6 @@ fn foo(i:int, j: @~str) -> foo {
|
|||
|
||||
fn main() {
|
||||
let cat = ~"kitty";
|
||||
let (_, ch) = Chan::new(); //~ ERROR does not fulfill `Send`
|
||||
ch.send(foo(42, @(cat))); //~ ERROR does not fulfill `Send`
|
||||
let (tx, _) = channel(); //~ ERROR does not fulfill `Send`
|
||||
tx.send(foo(42, @(cat))); //~ ERROR does not fulfill `Send`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,4 +67,4 @@ fn main() {
|
|||
}
|
||||
|
||||
#[inline(never)]
|
||||
fn zzz() { () }
|
||||
fn zzz() { () }
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ trait Foo : Bar { }
|
|||
impl <T: Send> Foo for T { }
|
||||
impl <T: Send> Bar for T { }
|
||||
|
||||
fn foo<T: Foo>(val: T, chan: Chan<T>) {
|
||||
fn foo<T: Foo>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
foo(31337, c);
|
||||
assert!(p.recv() == 31337);
|
||||
let (tx, rx) = channel();
|
||||
foo(31337, tx);
|
||||
assert!(rx.recv() == 31337);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,12 @@ struct X<T>(T);
|
|||
impl <T: Freeze> RequiresFreeze for X<T> { }
|
||||
impl <T: Freeze+Send> RequiresRequiresFreezeAndSend for X<T> { }
|
||||
|
||||
fn foo<T: RequiresRequiresFreezeAndSend>(val: T, chan: Chan<T>) {
|
||||
fn foo<T: RequiresRequiresFreezeAndSend>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
foo(X(31337), c);
|
||||
assert!(p.recv() == X(31337));
|
||||
let (tx, rx) = channel();
|
||||
foo(X(31337), tx);
|
||||
assert!(rx.recv() == X(31337));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ trait Foo : Send { }
|
|||
|
||||
impl <T: Send> Foo for T { }
|
||||
|
||||
fn foo<T: Foo>(val: T, chan: Chan<T>) {
|
||||
fn foo<T: Foo>(val: T, chan: Sender<T>) {
|
||||
chan.send(val);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
foo(31337, c);
|
||||
assert!(p.recv() == 31337);
|
||||
let (tx, rx) = channel();
|
||||
foo(31337, tx);
|
||||
assert!(rx.recv() == 31337);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,15 +12,15 @@
|
|||
// capabilities granted by builtin kinds as supertraits.
|
||||
|
||||
trait Foo : Send {
|
||||
fn foo(self, chan: Chan<Self>) {
|
||||
chan.send(self);
|
||||
fn foo(self, tx: Sender<Self>) {
|
||||
tx.send(self);
|
||||
}
|
||||
}
|
||||
|
||||
impl <T: Send> Foo for T { }
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
1193182.foo(c);
|
||||
assert!(p.recv() == 1193182);
|
||||
let (tx, rx) = channel();
|
||||
1193182.foo(tx);
|
||||
assert!(rx.recv() == 1193182);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,12 +26,12 @@
|
|||
|
||||
use std::task;
|
||||
|
||||
fn foo(x: ()) -> Port<()> {
|
||||
let (p, c) = Chan::<()>::new();
|
||||
fn foo(x: ()) -> Receiver<()> {
|
||||
let (tx, rx) = channel::<()>();
|
||||
task::spawn(proc() {
|
||||
c.send(x);
|
||||
tx.send(x);
|
||||
});
|
||||
p
|
||||
rx
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
extern crate native;
|
||||
|
||||
use std::fmt;
|
||||
use std::io::{PortReader, ChanWriter};
|
||||
use std::io::{ChanReader, ChanWriter};
|
||||
use std::logging::{set_logger, Logger};
|
||||
|
||||
struct MyWriter(ChanWriter);
|
||||
|
|
@ -36,8 +36,8 @@ fn start(argc: int, argv: **u8) -> int {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let (p, c) = Chan::new();
|
||||
let (mut r, w) = (PortReader::new(p), ChanWriter::new(c));
|
||||
let (tx, rx) = channel();
|
||||
let (mut r, w) = (ChanReader::new(rx), ChanWriter::new(tx));
|
||||
spawn(proc() {
|
||||
set_logger(~MyWriter(w) as ~Logger);
|
||||
debug!("debug");
|
||||
|
|
|
|||
|
|
@ -15,9 +15,9 @@ fn foo(blk: proc()) {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
foo(proc() {
|
||||
c.send(());
|
||||
tx.send(());
|
||||
});
|
||||
p.recv();
|
||||
rx.recv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,15 +11,15 @@
|
|||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
let (p, ch) = Chan::new();
|
||||
let _t = task::spawn(proc() { child(&ch) });
|
||||
let y = p.recv();
|
||||
let (tx, rx) = channel();
|
||||
let _t = task::spawn(proc() { child(&tx) });
|
||||
let y = rx.recv();
|
||||
error!("received");
|
||||
error!("{:?}", y);
|
||||
assert_eq!(y, 10);
|
||||
}
|
||||
|
||||
fn child(c: &Chan<int>) {
|
||||
fn child(c: &Sender<int>) {
|
||||
error!("sending");
|
||||
c.send(10);
|
||||
error!("value sent");
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ mod map_reduce {
|
|||
|
||||
pub type mapper = extern fn(~str, putter);
|
||||
|
||||
enum ctrl_proto { find_reducer(~[u8], Chan<int>), mapper_done, }
|
||||
enum ctrl_proto { find_reducer(~[u8], Sender<int>), mapper_done, }
|
||||
|
||||
fn start_mappers(ctrl: Chan<ctrl_proto>, inputs: ~[~str]) {
|
||||
fn start_mappers(ctrl: Sender<ctrl_proto>, inputs: ~[~str]) {
|
||||
for i in inputs.iter() {
|
||||
let ctrl = ctrl.clone();
|
||||
let i = i.clone();
|
||||
|
|
@ -41,20 +41,20 @@ mod map_reduce {
|
|||
}
|
||||
}
|
||||
|
||||
fn map_task(ctrl: Chan<ctrl_proto>, input: ~str) {
|
||||
fn map_task(ctrl: Sender<ctrl_proto>, input: ~str) {
|
||||
let mut intermediates = HashMap::new();
|
||||
|
||||
fn emit(im: &mut HashMap<~str, int>,
|
||||
ctrl: Chan<ctrl_proto>, key: ~str,
|
||||
ctrl: Sender<ctrl_proto>, key: ~str,
|
||||
_val: ~str) {
|
||||
if im.contains_key(&key) {
|
||||
return;
|
||||
}
|
||||
let (pp, cc) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
error!("sending find_reducer");
|
||||
ctrl.send(find_reducer(key.as_bytes().to_owned(), cc));
|
||||
ctrl.send(find_reducer(key.as_bytes().to_owned(), tx));
|
||||
error!("receiving");
|
||||
let c = pp.recv();
|
||||
let c = rx.recv();
|
||||
error!("{:?}", c);
|
||||
im.insert(key, c);
|
||||
}
|
||||
|
|
@ -65,7 +65,7 @@ mod map_reduce {
|
|||
}
|
||||
|
||||
pub fn map_reduce(inputs: ~[~str]) {
|
||||
let (ctrl_port, ctrl_chan) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
// This task becomes the master control task. It spawns others
|
||||
// to do the rest.
|
||||
|
|
@ -74,12 +74,12 @@ mod map_reduce {
|
|||
|
||||
reducers = HashMap::new();
|
||||
|
||||
start_mappers(ctrl_chan, inputs.clone());
|
||||
start_mappers(tx, inputs.clone());
|
||||
|
||||
let mut num_mappers = inputs.len() as int;
|
||||
|
||||
while num_mappers > 0 {
|
||||
match ctrl_port.recv() {
|
||||
match rx.recv() {
|
||||
mapper_done => { num_mappers -= 1; }
|
||||
find_reducer(k, cc) => {
|
||||
let mut c;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
extern crate extra;
|
||||
|
||||
use std::comm::Chan;
|
||||
use std::task;
|
||||
|
||||
type RingBuffer = ~[f64];
|
||||
|
|
@ -21,7 +20,7 @@ enum Msg
|
|||
GetSamples(~str, SamplesFn), // sample set name, callback which receives samples
|
||||
}
|
||||
|
||||
fn foo(name: ~str, samples_chan: Chan<Msg>) {
|
||||
fn foo(name: ~str, samples_chan: Sender<Msg>) {
|
||||
task::spawn(proc() {
|
||||
let mut samples_chan = samples_chan;
|
||||
let callback: SamplesFn = proc(buffer) {
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
use std::io::println;
|
||||
|
||||
pub fn main() {
|
||||
let (port, chan) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
spawn(proc() {
|
||||
println(port.recv());
|
||||
println(rx.recv());
|
||||
});
|
||||
|
||||
chan.send("hello, world");
|
||||
tx.send("hello, world");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,11 +11,11 @@
|
|||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
let (port, chan) = Chan::<&'static str>::new();
|
||||
let (tx, rx) = channel::<&'static str>();
|
||||
|
||||
task::spawn(proc() {
|
||||
assert_eq!(port.recv(), "hello, world");
|
||||
assert_eq!(rx.recv(), "hello, world");
|
||||
});
|
||||
|
||||
chan.send("hello, world");
|
||||
tx.send("hello, world");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ use std::comm;
|
|||
use std::io::timer::Timer;
|
||||
|
||||
pub fn main() {
|
||||
let (port, chan) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
spawn(proc (){
|
||||
let mut timer = Timer::new().unwrap();
|
||||
timer.sleep(10);
|
||||
chan.send(());
|
||||
tx.send(());
|
||||
});
|
||||
loop {
|
||||
match port.try_recv() {
|
||||
match rx.try_recv() {
|
||||
comm::Data(()) => break,
|
||||
comm::Empty => {}
|
||||
comm::Disconnected => unreachable!()
|
||||
|
|
|
|||
|
|
@ -10,17 +10,17 @@
|
|||
|
||||
use std::task;
|
||||
|
||||
fn producer(c: &Chan<~[u8]>) {
|
||||
c.send(
|
||||
fn producer(tx: &Sender<~[u8]>) {
|
||||
tx.send(
|
||||
~[1u8, 2u8, 3u8, 4u8, 5u8, 6u8, 7u8, 8u8, 9u8, 10u8, 11u8, 12u8,
|
||||
13u8]);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p, ch) = Chan::<~[u8]>::new();
|
||||
let (tx, rx) = channel::<~[u8]>();
|
||||
let _prod = task::spawn(proc() {
|
||||
producer(&ch)
|
||||
producer(&tx)
|
||||
});
|
||||
|
||||
let _data: ~[u8] = p.recv();
|
||||
let _data: ~[u8] = rx.recv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,13 @@ impl fmt::Show for Foo {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p,c) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
spawn(proc() {
|
||||
let mut f = Foo(Cell::new(0));
|
||||
debug!("{}", f);
|
||||
let Foo(ref mut f) = f;
|
||||
assert!(f.get() == 1);
|
||||
c.send(());
|
||||
tx.send(());
|
||||
});
|
||||
p.recv();
|
||||
rx.recv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ extern crate extra;
|
|||
use std::comm;
|
||||
use extra::comm;
|
||||
|
||||
fn starve_main(alive: Port<int>) {
|
||||
fn starve_main(alive: Receiver<int>) {
|
||||
info!("signalling main");
|
||||
alive.recv();
|
||||
info!("starving main");
|
||||
|
|
|
|||
|
|
@ -25,14 +25,14 @@ fn test(f: int) -> test {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p, c) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
task::spawn(proc() {
|
||||
let (pp, cc) = Chan::new();
|
||||
c.send(cc);
|
||||
let (tx2, rx2) = channel();
|
||||
tx.send(tx2);
|
||||
|
||||
let _r = pp.recv();
|
||||
let _r = rx2.recv();
|
||||
});
|
||||
|
||||
p.recv().send(test(42));
|
||||
rx.recv().send(test(42));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ struct Command<K, V> {
|
|||
val: V
|
||||
}
|
||||
|
||||
fn cache_server<K:Send,V:Send>(mut c: Chan<Chan<Command<K, V>>>) {
|
||||
let (_ctrl_port, ctrl_chan) = Chan::new();
|
||||
c.send(ctrl_chan);
|
||||
fn cache_server<K:Send,V:Send>(mut tx: Sender<Sender<Command<K, V>>>) {
|
||||
let (tx1, _rx) = channel();
|
||||
tx.send(tx1);
|
||||
}
|
||||
pub fn main() { }
|
||||
|
|
|
|||
|
|
@ -23,6 +23,6 @@ fn foo(i:int, j: char) -> foo {
|
|||
}
|
||||
|
||||
pub fn main() {
|
||||
let (_po, ch) = Chan::new();
|
||||
ch.send(foo(42, 'c'));
|
||||
let (tx, rx) = channel();
|
||||
tx.send(foo(42, 'c'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
use std::task;
|
||||
|
||||
type ctx = Chan<int>;
|
||||
type ctx = Sender<int>;
|
||||
|
||||
fn iotask(_cx: &ctx, ip: ~str) {
|
||||
fn iotask(_tx: &ctx, ip: ~str) {
|
||||
assert_eq!(ip, ~"localhost");
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (_p, ch) = Chan::<int>::new();
|
||||
task::spawn(proc() iotask(&ch, ~"localhost") );
|
||||
let (tx, _rx) = channel::<int>();
|
||||
task::spawn(proc() iotask(&tx, ~"localhost") );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,23 +16,23 @@ use std::task;
|
|||
|
||||
pub fn main() { test05(); }
|
||||
|
||||
fn test05_start(ch : &Chan<int>) {
|
||||
ch.send(10);
|
||||
fn test05_start(tx : &Sender<int>) {
|
||||
tx.send(10);
|
||||
error!("sent 10");
|
||||
ch.send(20);
|
||||
tx.send(20);
|
||||
error!("sent 20");
|
||||
ch.send(30);
|
||||
tx.send(30);
|
||||
error!("sent 30");
|
||||
}
|
||||
|
||||
fn test05() {
|
||||
let (po, ch) = Chan::new();
|
||||
task::spawn(proc() { test05_start(&ch) });
|
||||
let mut value: int = po.recv();
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(proc() { test05_start(&tx) });
|
||||
let mut value: int = rx.recv();
|
||||
error!("{}", value);
|
||||
value = po.recv();
|
||||
value = rx.recv();
|
||||
error!("{}", value);
|
||||
value = po.recv();
|
||||
value = rx.recv();
|
||||
error!("{}", value);
|
||||
assert_eq!(value, 30);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,25 +14,25 @@ extern crate extra;
|
|||
|
||||
use std::task;
|
||||
|
||||
fn start(c: &Chan<Chan<~str>>) {
|
||||
let (p, ch) = Chan::new();
|
||||
c.send(ch);
|
||||
fn start(tx: &Sender<Sender<~str>>) {
|
||||
let (tx2, rx) = channel();
|
||||
tx.send(tx2);
|
||||
|
||||
let mut a;
|
||||
let mut b;
|
||||
a = p.recv();
|
||||
a = rx.recv();
|
||||
assert!(a == ~"A");
|
||||
error!("{:?}", a);
|
||||
b = p.recv();
|
||||
b = rx.recv();
|
||||
assert!(b == ~"B");
|
||||
error!("{:?}", b);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p, ch) = Chan::new();
|
||||
let _child = task::spawn(proc() { start(&ch) });
|
||||
let (tx, rx) = channel();
|
||||
let _child = task::spawn(proc() { start(&tx) });
|
||||
|
||||
let mut c = p.recv();
|
||||
let mut c = rx.recv();
|
||||
c.send(~"A");
|
||||
c.send(~"B");
|
||||
task::deschedule();
|
||||
|
|
|
|||
|
|
@ -14,15 +14,15 @@ extern crate extra;
|
|||
|
||||
use std::task;
|
||||
|
||||
fn start(c: &Chan<Chan<int>>) {
|
||||
let (_p, ch) = Chan::new();
|
||||
c.send(ch);
|
||||
fn start(tx: &Sender<Sender<int>>) {
|
||||
let (tx2, _rx) = channel();
|
||||
tx.send(tx2);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (mut p, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let _child = task::spawn(proc() {
|
||||
start(&ch)
|
||||
start(&tx)
|
||||
});
|
||||
let _c = p.recv();
|
||||
let _tx = rx.recv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,14 +14,14 @@ extern crate extra;
|
|||
|
||||
use std::task;
|
||||
|
||||
fn start(c: &Chan<int>, start: int, number_of_messages: int) {
|
||||
fn start(tx: &Sender<int>, start: int, number_of_messages: int) {
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
while i < number_of_messages { tx.send(start + i); i += 1; }
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
info!("Check that we don't deadlock.");
|
||||
let (_p, ch) = Chan::new();
|
||||
task::try(proc() { start(&ch, 0, 10) });
|
||||
let (tx, rx) = channel();
|
||||
task::try(proc() { start(&tx, 0, 10) });
|
||||
info!("Joined task");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,14 +13,14 @@
|
|||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
let (po, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
// Spawn 10 tasks each sending us back one int.
|
||||
let mut i = 10;
|
||||
while (i > 0) {
|
||||
info!("{}", i);
|
||||
let ch = ch.clone();
|
||||
task::spawn({let i = i; proc() { child(i, &ch) }});
|
||||
let tx = tx.clone();
|
||||
task::spawn({let i = i; proc() { child(i, &tx) }});
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
|
|
@ -30,14 +30,14 @@ pub fn main() {
|
|||
i = 10;
|
||||
while (i > 0) {
|
||||
info!("{}", i);
|
||||
po.recv();
|
||||
rx.recv();
|
||||
i = i - 1;
|
||||
}
|
||||
|
||||
info!("main thread exiting");
|
||||
}
|
||||
|
||||
fn child(x: int, ch: &Chan<int>) {
|
||||
fn child(x: int, tx: &Sender<int>) {
|
||||
info!("{}", x);
|
||||
ch.send(x);
|
||||
tx.send(x);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ extern crate extra;
|
|||
|
||||
use std::task;
|
||||
|
||||
fn start(c: &Chan<int>, i0: int) {
|
||||
fn start(tx: &Sender<int>, i0: int) {
|
||||
let mut i = i0;
|
||||
while i > 0 {
|
||||
c.send(0);
|
||||
tx.send(0);
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -27,10 +27,9 @@ pub fn main() {
|
|||
// is likely to terminate before the child completes, so from
|
||||
// the child's point of view the receiver may die. We should
|
||||
// drop messages on the floor in this case, and not crash!
|
||||
let (p, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(proc() {
|
||||
let mut ch = ch;
|
||||
start(&ch, 10)
|
||||
start(&tx, 10)
|
||||
});
|
||||
p.recv();
|
||||
rx.recv();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,31 +14,31 @@ use std::cmp;
|
|||
fn test_rec() {
|
||||
struct R {val0: int, val1: u8, val2: char}
|
||||
|
||||
let (po, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let r0: R = R {val0: 0, val1: 1u8, val2: '2'};
|
||||
ch.send(r0);
|
||||
tx.send(r0);
|
||||
let mut r1: R;
|
||||
r1 = po.recv();
|
||||
r1 = rx.recv();
|
||||
assert_eq!(r1.val0, 0);
|
||||
assert_eq!(r1.val1, 1u8);
|
||||
assert_eq!(r1.val2, '2');
|
||||
}
|
||||
|
||||
fn test_vec() {
|
||||
let (po, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let v0: ~[int] = ~[0, 1, 2];
|
||||
ch.send(v0);
|
||||
let v1 = po.recv();
|
||||
tx.send(v0);
|
||||
let v1 = rx.recv();
|
||||
assert_eq!(v1[0], 0);
|
||||
assert_eq!(v1[1], 1);
|
||||
assert_eq!(v1[2], 2);
|
||||
}
|
||||
|
||||
fn test_str() {
|
||||
let (po, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let s0 = ~"test";
|
||||
ch.send(s0);
|
||||
let s1 = po.recv();
|
||||
tx.send(s0);
|
||||
let s1 = rx.recv();
|
||||
assert_eq!(s1[0], 't' as u8);
|
||||
assert_eq!(s1[1], 'e' as u8);
|
||||
assert_eq!(s1[2], 's' as u8);
|
||||
|
|
@ -80,29 +80,29 @@ impl cmp::Eq for t {
|
|||
}
|
||||
|
||||
fn test_tag() {
|
||||
let (po, ch) = Chan::new();
|
||||
ch.send(tag1);
|
||||
ch.send(tag2(10));
|
||||
ch.send(tag3(10, 11u8, 'A'));
|
||||
let (tx, rx) = channel();
|
||||
tx.send(tag1);
|
||||
tx.send(tag2(10));
|
||||
tx.send(tag3(10, 11u8, 'A'));
|
||||
let mut t1: t;
|
||||
t1 = po.recv();
|
||||
t1 = rx.recv();
|
||||
assert_eq!(t1, tag1);
|
||||
t1 = po.recv();
|
||||
t1 = rx.recv();
|
||||
assert_eq!(t1, tag2(10));
|
||||
t1 = po.recv();
|
||||
t1 = rx.recv();
|
||||
assert_eq!(t1, tag3(10, 11u8, 'A'));
|
||||
}
|
||||
|
||||
fn test_chan() {
|
||||
let (po, ch) = Chan::new();
|
||||
let (po0, ch0) = Chan::new();
|
||||
ch.send(ch0);
|
||||
let mut ch1 = po.recv();
|
||||
let (tx1, rx1) = channel();
|
||||
let (tx2, rx2) = channel();
|
||||
tx1.send(tx2);
|
||||
let tx2 = rx1.recv();
|
||||
// Does the transmitted channel still work?
|
||||
|
||||
ch1.send(10);
|
||||
tx2.send(10);
|
||||
let mut i: int;
|
||||
i = po0.recv();
|
||||
i = rx2.recv();
|
||||
assert_eq!(i, 10);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use std::task;
|
|||
|
||||
pub fn main() { info!("===== WITHOUT THREADS ====="); test00(); }
|
||||
|
||||
fn test00_start(ch: &Chan<int>, message: int, count: int) {
|
||||
fn test00_start(ch: &Sender<int>, message: int, count: int) {
|
||||
info!("Starting test00_start");
|
||||
let mut i: int = 0;
|
||||
while i < count {
|
||||
|
|
@ -33,21 +33,20 @@ fn test00() {
|
|||
|
||||
info!("Creating tasks");
|
||||
|
||||
let (po, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
|
||||
let mut i: int = 0;
|
||||
|
||||
// Create and spawn tasks...
|
||||
let mut results = ~[];
|
||||
while i < number_of_tasks {
|
||||
let ch = ch.clone();
|
||||
let tx = tx.clone();
|
||||
let mut builder = task::task();
|
||||
results.push(builder.future_result());
|
||||
builder.spawn({
|
||||
let ch = ch;
|
||||
let i = i;
|
||||
proc() {
|
||||
test00_start(&ch, i, number_of_messages)
|
||||
test00_start(&tx, i, number_of_messages)
|
||||
}
|
||||
});
|
||||
i = i + 1;
|
||||
|
|
@ -58,7 +57,7 @@ fn test00() {
|
|||
for _r in results.iter() {
|
||||
i = 0;
|
||||
while i < number_of_messages {
|
||||
let value = po.recv();
|
||||
let value = rx.recv();
|
||||
sum += value;
|
||||
i = i + 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,37 +15,37 @@ pub fn main() { test00(); }
|
|||
fn test00() {
|
||||
let mut r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (p, c) = Chan::new();
|
||||
c.send(1);
|
||||
c.send(2);
|
||||
c.send(3);
|
||||
c.send(4);
|
||||
r = p.recv();
|
||||
let (tx, rx) = channel();
|
||||
tx.send(1);
|
||||
tx.send(2);
|
||||
tx.send(3);
|
||||
tx.send(4);
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
c.send(5);
|
||||
c.send(6);
|
||||
c.send(7);
|
||||
c.send(8);
|
||||
r = p.recv();
|
||||
tx.send(5);
|
||||
tx.send(6);
|
||||
tx.send(7);
|
||||
tx.send(8);
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
info!("{}", r);
|
||||
assert_eq!(sum, 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8);
|
||||
|
|
|
|||
|
|
@ -15,11 +15,11 @@ pub fn main() { test00(); }
|
|||
fn test00() {
|
||||
let _r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (p, c) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let number_of_messages: int = 1000;
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { c.send(i + 0); i += 1; }
|
||||
while i < number_of_messages { tx.send(i + 0); i += 1; }
|
||||
i = 0;
|
||||
while i < number_of_messages { sum += p.recv(); i += 1; }
|
||||
while i < number_of_messages { sum += rx.recv(); i += 1; }
|
||||
assert_eq!(sum, number_of_messages * (number_of_messages - 1) / 2);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,29 +15,29 @@ pub fn main() { test00(); }
|
|||
fn test00() {
|
||||
let mut r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (p, ch) = Chan::new();
|
||||
let mut c0 = ch.clone();
|
||||
let mut c1 = ch.clone();
|
||||
let mut c2 = ch.clone();
|
||||
let mut c3 = ch.clone();
|
||||
let (tx, rx) = channel();
|
||||
let mut tx0 = tx.clone();
|
||||
let mut tx1 = tx.clone();
|
||||
let mut tx2 = tx.clone();
|
||||
let mut tx3 = tx.clone();
|
||||
let number_of_messages: int = 1000;
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
c0.send(i + 0);
|
||||
c1.send(i + 0);
|
||||
c2.send(i + 0);
|
||||
c3.send(i + 0);
|
||||
tx0.send(i + 0);
|
||||
tx1.send(i + 0);
|
||||
tx2.send(i + 0);
|
||||
tx3.send(i + 0);
|
||||
i += 1;
|
||||
}
|
||||
i = 0;
|
||||
while i < number_of_messages {
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use std::task;
|
|||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: &Chan<int>, start: int,
|
||||
fn test00_start(c: &Sender<int>, start: int,
|
||||
number_of_messages: int) {
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { c.send(start + i); i += 1; }
|
||||
|
|
@ -27,35 +27,35 @@ fn test00_start(c: &Chan<int>, start: int,
|
|||
fn test00() {
|
||||
let mut r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (p, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let c = ch.clone();
|
||||
let tx2 = tx.clone();
|
||||
task::spawn(proc() {
|
||||
test00_start(&c, number_of_messages * 0, number_of_messages);
|
||||
test00_start(&tx2, number_of_messages * 0, number_of_messages);
|
||||
});
|
||||
let c = ch.clone();
|
||||
let tx2 = tx.clone();
|
||||
task::spawn(proc() {
|
||||
test00_start(&c, number_of_messages * 1, number_of_messages);
|
||||
test00_start(&tx2, number_of_messages * 1, number_of_messages);
|
||||
});
|
||||
let c = ch.clone();
|
||||
let tx2 = tx.clone();
|
||||
task::spawn(proc() {
|
||||
test00_start(&c, number_of_messages * 2, number_of_messages);
|
||||
test00_start(&tx2, number_of_messages * 2, number_of_messages);
|
||||
});
|
||||
let c = ch.clone();
|
||||
let tx2 = tx.clone();
|
||||
task::spawn(proc() {
|
||||
test00_start(&c, number_of_messages * 3, number_of_messages);
|
||||
test00_start(&tx2, number_of_messages * 3, number_of_messages);
|
||||
});
|
||||
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
r = p.recv();
|
||||
r = rx.recv();
|
||||
sum += r;
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use std::task;
|
|||
|
||||
pub fn main() { test00(); }
|
||||
|
||||
fn test00_start(c: &Chan<int>, number_of_messages: int) {
|
||||
fn test00_start(c: &Sender<int>, number_of_messages: int) {
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages { c.send(i + 0); i += 1; }
|
||||
}
|
||||
|
|
@ -24,19 +24,18 @@ fn test00_start(c: &Chan<int>, number_of_messages: int) {
|
|||
fn test00() {
|
||||
let r: int = 0;
|
||||
let mut sum: int = 0;
|
||||
let (p, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let number_of_messages: int = 10;
|
||||
|
||||
let mut builder = task::task();
|
||||
let result = builder.future_result();
|
||||
builder.spawn(proc() {
|
||||
let mut ch = ch;
|
||||
test00_start(&mut ch, number_of_messages);
|
||||
test00_start(&tx, number_of_messages);
|
||||
});
|
||||
|
||||
let mut i: int = 0;
|
||||
while i < number_of_messages {
|
||||
sum += p.recv();
|
||||
sum += rx.recv();
|
||||
info!("{:?}", r);
|
||||
i += 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ extern crate extra;
|
|||
// any size, but rustc currently can because they do have size. Whether
|
||||
// or not this is desirable I don't know, but here's a regression test.
|
||||
pub fn main() {
|
||||
let (po, ch) = Chan::new();
|
||||
ch.send(());
|
||||
let n: () = po.recv();
|
||||
let (tx, rx) = channel();
|
||||
tx.send(());
|
||||
let n: () = rx.recv();
|
||||
assert_eq!(n, ());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,16 +11,16 @@
|
|||
use std::task;
|
||||
|
||||
pub fn main() {
|
||||
let (p, ch) = Chan::<uint>::new();
|
||||
let (tx, rx) = channel::<uint>();
|
||||
|
||||
let x = ~1;
|
||||
let x_in_parent = &(*x) as *int as uint;
|
||||
|
||||
task::spawn(proc() {
|
||||
let x_in_child = &(*x) as *int as uint;
|
||||
ch.send(x_in_child);
|
||||
tx.send(x_in_child);
|
||||
});
|
||||
|
||||
let x_in_child = p.recv();
|
||||
let x_in_child = rx.recv();
|
||||
assert_eq!(x_in_parent, x_in_child);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,14 +38,14 @@ fn test_tempdir() {
|
|||
}
|
||||
|
||||
fn test_rm_tempdir() {
|
||||
let (rd, wr) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let f: proc() = proc() {
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
wr.send(tmp.path().clone());
|
||||
tx.send(tmp.path().clone());
|
||||
fail!("fail to unwind past `tmp`");
|
||||
};
|
||||
task::try(f);
|
||||
let path = rd.recv();
|
||||
let path = rx.recv();
|
||||
assert!(!path.exists());
|
||||
|
||||
let tmp = TempDir::new("test_rm_tempdir").unwrap();
|
||||
|
|
|
|||
|
|
@ -69,18 +69,18 @@ pub fn main() {
|
|||
~dogge1 as ~Pet:Freeze+Send,
|
||||
~fishe as ~Pet:Freeze+Send,
|
||||
~dogge2 as ~Pet:Freeze+Send]);
|
||||
let (p1,c1) = Chan::new();
|
||||
let (tx1, rx1) = channel();
|
||||
let arc1 = arc.clone();
|
||||
task::spawn(proc() { check_legs(arc1); c1.send(()); });
|
||||
let (p2,c2) = Chan::new();
|
||||
task::spawn(proc() { check_legs(arc1); tx1.send(()); });
|
||||
let (tx2, rx2) = channel();
|
||||
let arc2 = arc.clone();
|
||||
task::spawn(proc() { check_names(arc2); c2.send(()); });
|
||||
let (p3,c3) = Chan::new();
|
||||
task::spawn(proc() { check_names(arc2); tx2.send(()); });
|
||||
let (tx3, rx3) = channel();
|
||||
let arc3 = arc.clone();
|
||||
task::spawn(proc() { check_pedigree(arc3); c3.send(()); });
|
||||
p1.recv();
|
||||
p2.recv();
|
||||
p3.recv();
|
||||
task::spawn(proc() { check_pedigree(arc3); tx3.send(()); });
|
||||
rx1.recv();
|
||||
rx2.recv();
|
||||
rx3.recv();
|
||||
}
|
||||
|
||||
fn check_legs(arc: Arc<~[~Pet:Freeze+Send]>) {
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@
|
|||
*/
|
||||
|
||||
pub fn main() {
|
||||
let (po, ch) = Chan::new();
|
||||
ch.send(42);
|
||||
let r = po.recv();
|
||||
let (tx, rx) = channel();
|
||||
tx.send(42);
|
||||
let r = rx.recv();
|
||||
error!("{:?}", r);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,25 +10,25 @@
|
|||
|
||||
use std::task;
|
||||
|
||||
fn child(c: &Chan<~uint>, i: uint) {
|
||||
c.send(~i);
|
||||
fn child(tx: &Sender<~uint>, i: uint) {
|
||||
tx.send(~i);
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p, ch) = Chan::new();
|
||||
let (tx, rx) = channel();
|
||||
let n = 100u;
|
||||
let mut expected = 0u;
|
||||
for i in range(0u, n) {
|
||||
let ch = ch.clone();
|
||||
let tx = tx.clone();
|
||||
task::spawn(proc() {
|
||||
child(&ch, i)
|
||||
child(&tx, i)
|
||||
});
|
||||
expected += i;
|
||||
}
|
||||
|
||||
let mut actual = 0u;
|
||||
for _ in range(0u, n) {
|
||||
let j = p.recv();
|
||||
let j = rx.recv();
|
||||
actual += *j;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
pub fn main() {
|
||||
let (p, c) = Chan::new();
|
||||
c.send(~100);
|
||||
let v = p.recv();
|
||||
let (tx, rx) = channel();
|
||||
tx.send(~100);
|
||||
let v = rx.recv();
|
||||
assert_eq!(v, ~100);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,32 +15,32 @@ extern crate extra;
|
|||
use std::task;
|
||||
|
||||
struct complainer {
|
||||
c: Chan<bool>,
|
||||
tx: Sender<bool>,
|
||||
}
|
||||
|
||||
impl Drop for complainer {
|
||||
fn drop(&mut self) {
|
||||
error!("About to send!");
|
||||
self.c.send(true);
|
||||
self.tx.send(true);
|
||||
error!("Sent!");
|
||||
}
|
||||
}
|
||||
|
||||
fn complainer(c: Chan<bool>) -> complainer {
|
||||
fn complainer(tx: Sender<bool>) -> complainer {
|
||||
error!("Hello!");
|
||||
complainer {
|
||||
c: c
|
||||
tx: tx
|
||||
}
|
||||
}
|
||||
|
||||
fn f(c: Chan<bool>) {
|
||||
let _c = complainer(c);
|
||||
fn f(tx: Sender<bool>) {
|
||||
let _tx = complainer(tx);
|
||||
fail!();
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
let (p, c) = Chan::new();
|
||||
task::spawn(proc() f(c.clone()));
|
||||
let (tx, rx) = channel();
|
||||
task::spawn(proc() f(tx.clone()));
|
||||
error!("hiiiiiiiii");
|
||||
assert!(p.recv());
|
||||
assert!(rx.recv());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue