Wafer icon indicating copy to clipboard operation
Wafer copied to clipboard

Push data write to thread

Open Libbum opened this issue 7 years ago • 3 comments

Since we have w_store persistent, we can send of the file writes to a future or rayon thread.

Libbum avatar May 18 '17 21:05 Libbum

Potentials is also a candidate obviously, and it's really needed. For large grids these files can take ages to dump.

Libbum avatar May 25 '17 22:05 Libbum

OK. Think I have a proof of concept for this now.

use std::sync::mpsc::channel;
use std::time::Duration;
use std::thread;

fn calculate_data() -> u32 {
    5
}

fn save_data(data: &u32) {
    thread::sleep(Duration::from_secs(1));
    println!("Saving data: {}", data);
}

fn main() {

let (sender, receiver) = channel();

let save = thread::spawn(move|| {
    let data = calculate_data(); //Run calculation
    sender.send(data).unwrap(); //Send result to main thread
    save_data(&data); //Save data to disk in current thread
});

//data is now available in main thread
println!("{:?}", receiver.recv().unwrap());

save.join().unwrap(); //Blocks until data is written.
println!("done");
}

Libbum avatar Aug 09 '17 15:08 Libbum