Skip to content

Commit 7c79b5e

Browse files
tedhorstcatamorphism
authored andcommitted
really update mandelbrot to pipes
1 parent b169889 commit 7c79b5e

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/test/bench/shootout-mandelbrot.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn fillbyte(x: cmplx, incr: f64) -> u8 {
8383
rv
8484
}
8585

86-
fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
86+
fn chanmb(i: uint, size: uint) -> Line
8787
{
8888
let mut crv = ~[];
8989
let incr = 2f64/(size as f64);
@@ -93,7 +93,7 @@ fn chanmb(i: uint, size: uint, ch: oldcomm::Chan<Line>) -> ()
9393
let x = cmplx {re: xincr*(j as f64) - 1.5f64, im: y};
9494
crv.push(fillbyte(x, incr));
9595
};
96-
oldcomm::send(ch, Line {i:i, b: move crv});
96+
Line {i:i, b:crv}
9797
}
9898

9999
type devnull = {dn: int};
@@ -106,11 +106,8 @@ impl devnull: io::Writer {
106106
fn get_type(&self) -> io::WriterType { io::File }
107107
}
108108

109-
fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
109+
fn writer(path: ~str, pport: pipes::Port<Line>, size: uint)
110110
{
111-
let p: oldcomm::Port<Line> = oldcomm::Port();
112-
let ch = oldcomm::Chan(&p);
113-
oldcomm::send(writech, ch);
114111
let cout: io::Writer = match path {
115112
~"" => {
116113
{dn: 0} as io::Writer
@@ -130,7 +127,7 @@ fn writer(path: ~str, writech: oldcomm::Chan<oldcomm::Chan<Line>>, size: uint)
130127
let mut done = 0_u;
131128
let mut i = 0_u;
132129
while i < size {
133-
let aline = oldcomm::recv(p);
130+
let aline = pport.recv();
134131
if aline.i == done {
135132
debug!("W %u", aline.i);
136133
cout.write(aline.b);
@@ -171,13 +168,11 @@ fn main() {
171168
let size = if vec::len(args) < 2_u { 80_u }
172169
else { uint::from_str(args[1]).get() };
173170

174-
let writep = oldcomm::Port();
175-
let writech = oldcomm::Chan(&writep);
176-
do task::spawn |move path| {
177-
writer(copy path, writech, size);
178-
};
179-
let ch = oldcomm::recv(writep);
171+
let (pport, pchan) = pipes::stream();
172+
let pchan = pipes::SharedChan(pchan);
180173
for uint::range(0_u, size) |j| {
181-
do task::spawn { chanmb(j, size, ch) };
174+
let cchan = pchan.clone();
175+
do task::spawn |move cchan| { cchan.send(chanmb(j, size)) };
182176
};
177+
writer(path, pport, size);
183178
}

0 commit comments

Comments
 (0)