Closed
Description
Depending on number of threads and steal results this test case may livelock, and probably exhaust memory:
fn periodical(n: int) -> Port<bool> {
let (port, chan) = stream();
do spawn {
println(fmt!("periodical %d - begin", n));
loop {
for _ in range(1, n) {
println(fmt!("periodical %d - sending...", n));
chan.send(false);
println(fmt!("periodical %d - sent", n));
}
chan.send(true);
}
}
return port;
}
fn integers() -> Port<int> {
let (port, chan) = stream();
do spawn {
println("integers - begin");
let mut i = 1;
loop {
chan.send(i);
i = i + 1;
}
}
return port;
}
fn main() {
let ints = integers();
let threes = periodical(3);
let fives = periodical(5);
for _ in range(1, 100) {
match (ints.recv(), threes.recv(), fives.recv()) {
(_, true, true) => println("FizzBuzz"),
(_, true, false) => println("Fizz"),
(_, false, true) => println("Buzz"),
(i, false, false) => println(fmt!("%d", i))
}
}
}