extern crate rb;
use rb::*;
use std::thread;
fn main() {
const SIZE: usize = 128;
let rb = SpscRb::new(SIZE);
let (prod, cons) = (rb.producer(), rb.consumer());
const PERIOD: usize = 16;
thread::spawn(move || {
let mut skip = 0;
let saw = || {
((PERIOD as isize / -2)..(PERIOD as isize / 2 + 1))
.cycle()
.map(|x| x as f32 / (PERIOD / 2) as f32)
};
loop {
let cnt = prod.write_blocking(&saw().skip(skip).take(PERIOD).collect::<Vec<f32>>())
.unwrap();
skip += cnt % (PERIOD);
}
});
let mut data = Vec::with_capacity(SIZE);
let mut buf = [0.0f32; SIZE / 4];
while data.len() < SIZE {
let cnt = cons.read_blocking(&mut buf).unwrap();
data.extend_from_slice(&buf[..cnt]);
}
println!("{:?}", &data[..PERIOD]);
}