Skip to content

Instantly share code, notes, and snippets.

@thoughtpolice
Created October 23, 2011 23:03
Show Gist options
  • Save thoughtpolice/1308042 to your computer and use it in GitHub Desktop.
Save thoughtpolice/1308042 to your computer and use it in GitHub Desktop.
use std;
import std::io;
import std::uint;
import std::task;
import std::comm;
type d = { ch: comm::chan<uint>, i: uint };
fn runner(c: d) {
let z = c.i; // Satisfy move semantics for send
log "Sending " + uint::to_str(z, 10u);
comm::send(c.ch, z);
}
fn main() {
let p = comm::port();
let c = comm::chan(p);
uint::range(0u, 10u) { |i|
log "Launching " + uint::to_str(i, 10u);
task::spawn({ch: c, i: i}, runner);
};
let x = 0u;
while x < 10u {
let r = comm::recv(p);
log "Result: " + uint::to_str(r, 10u);
x += 1u;
}
io::println("Done");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment