// Background thread to generate gaussian values
Background thread to generate gaussian values
Background thread to generate gaussian values
fn start_normal_generator() -> Receiver<f64> {
    // sync channel will buffer until full then block the thread
    let (tx, rx) = sync_channel(32768);
    debug!("Starting gaussian thread...");
    thread::spawn(move|| {
        ::GENERATOR_RUNNING.store(true, Ordering::SeqCst);
        let normal = Normal::new(0.0, 1.0);
        let mut counter = 0;
        loop {
            let v = normal.ind_sample(&mut thread_rng());
            match tx.try_send(v) {
                Ok(_) => {},
                Err(_) => thread::sleep_ms(50)
            }
            if counter > 1024 {
                counter = 0;
                if ::GENERATOR_RUNNING.load(Ordering::SeqCst) == false {
                    break;
                }
            }
            counter += 1;
        }
    });
    rx
}
fn start_normal_generator ( ) -> Receiver < f64 > { // sync channel will buffer until full then block the thread let ( tx , rx ) = sync_channel ( 32768 ) ; debug ! ( " " ) ; thread :: spawn ( move | | { :: GENERATOR_RUNNING . store ( true , Ordering :: SeqCst ) ; let normal = Normal :: new ( 0.0 , 1.0 ) ; let mut counter = 0 ; loop { let v = normal . ind_sample ( & mut thread_rng ( ) ) ; match tx . try_send ( v ) { Ok ( _ ) => { } , Err ( _ ) => thread :: sleep_ms ( 50 ) } if counter > 1024 { counter = 0 ; if :: GENERATOR_RUNNING . load ( Ordering :: SeqCst ) == false { break ; } } counter += 1 ; } } ) ; rx }
Background thread to generate gaussian values
Background thread to generate gaussian values