Skip to content

Instantly share code, notes, and snippets.

@ayosec
Last active August 29, 2015 14:06
Show Gist options
  • Save ayosec/b1386b3afcdc38eaefef to your computer and use it in GitHub Desktop.
Save ayosec/b1386b3afcdc38eaefef to your computer and use it in GitHub Desktop.
Rust mpmc_bounded_queue::Queue
use std::sync::mpmc_bounded_queue::Queue;
use std::io::Timer;
use std::time::Duration;
fn main() {
let queue: Queue<i8> = Queue::with_capacity(10);
queue.push(0);
let q1 = queue.clone();
spawn(proc() {
q1.push(10);
q1.push(11);
q1.push(12);
});
let q2 = queue.clone();
spawn(proc() {
println!("proc {}", q2.pop());
});
let mut timer = Timer::new().unwrap();
timer.sleep(Duration::milliseconds(10));
loop {
match queue.pop() {
Some(x) => println!("main {}", x),
None => break
}
}
println!("END");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment