I have a source file called input.iso
and I want to write its content to /dev/sdx
in a separate thread. I also have a written: Arc<RefCell<usize>>
keep track of of the copy progress. I have to_write: Arc<usize>
too. I also need to be able to know if the writer thread finished successfully.
I need to be able to display progress of this progress. I have a timer function running in the UI thread that periodically is going to read the progress
. How can I achieve this?
I'm stuck because
-
I don't know how to determine if a thread finished.
thread::spawn
returns a join handle. -
the
write
method returns how many bytes that have been written. How can I start from that amount of byte ininput.iso
next time I callwrite
?
Here's a rough sketch of what I want to achieve:
fn set_start() {
let written = Arc::<usize>::new(0);
let to_write = get_size();
let (input, output) = get_io();
let task = thread::spawn(move ||{
// written += write;
});
let progress_bar = make_pb();
let pb_timeout = gtk::timeout_add(
20 /*interval*/,
|_| {
// check written
// do something with written
return task.finished;
}
)
}