Created
October 23, 2011 23:03
-
-
Save thoughtpolice/1308042 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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