How can I move reference into new thread in my case?
// How can I move reference into new thread?
pub mod tds {
use std::thread;
use std::thread::JoinHandle;
pub fn f(sts: &u8) -> JoinHandle<()> {
thread::spawn(move || {
*sts = 88;
println!("flow: {:?}", sts);
})
}
}
fn main() {
let mut sts: u8 = 5;
let handle = tds::f(&sts);
println!("main_01: {:?}", sts);
handle.join().unwrap();
println!("main_02: {:?}", sts);
}
I found some link but couldn't apply, text
One solution is scoped threads — threads that are guaranteed to exit before the parent thread exits. These can ensure that stack variables in the parent thread will be available for the entire duration of the thread.