I'm currently moving a project from Python to Rust, and I ran into a small problem with the concept of ownership in Rust.
My main thread create a empty vector, then, I start another thread and that thread will run forever (loop) and add data to the vector every second. Until here, no problem.
The problem comes when from my main thread, I want to read the vector (print it or use the data inside it). Since the ownership has been moved, I can't use the vector in my main thread.
let mut prices: Vec<f64> = Vec::new();
thread::spawn(move || {
start_filling_prices(&mut prices);
});
println!("{:?}", prices);
^^^^^^^ value borrowed here after move
I've tried using a Mutex, Arc, Box, but the same problem occurs every time (or maybe I used the wrong one).
So, does someone know how to use the same variable in different threads at the same time?