How can I modify data by muti-threading


Hi, guys, I’m just starting to use Rust recently, here is a question:
when I have a Vec data, and I want to modify each of it’s elements in a different thread, how can I achieve this?
for example:
struct ABC{



fn main() {

let mut x1=ABC{a:"first".to_string(), b:1};
let mut x2=ABC{a:"second".to_string(), b:2};
let mut x3=ABC{a:"second".to_string(), b:3};
let all=vec![x1, x2, x3];

let mut ths=Vec::new();
let data=Arc::new(Mutex::new(all));
for i in 0usize..3 {
	let mut data=data.clone();
	let t=std::thread::spawn(move || {
		let mut p=data.lock().unwrap();

for i in ths {


BUT, this comes to be just a blocked way, because each thread takes the ownership until data has been fully processed. So, how can I change to make it happen simultaneously?


I suggest using rayon or jobsteal since they provide parallel iterators. I’ve compared some parallelization crates here: mandel-rust.

So your code would look like this (untested):

         .for_each(|element| *element.b += 1);


I’ll try them, thank you