[Solved] Rust thread errors

There are 2 errors in this code:

 let _ks = partition_data(num_partitions,&v);`
 let mut vc : Vec<usize> = Vec::new();` 
 for i in 0..num_partitions{ 
     let p2 = _ks[i].clone(); 
     let tt2 = thread::spawn(move || {map_data(&p2)}); 
     vc.push(tt2)
 } 
 for entry in vc{` 
    intermediate_sums.push(entry.join().unwrap());` 
 }

The first one is with ttt2 in 'vv.push(tt2)' expected usize, found struct std::thread::JoinHandle
The second one is .join in 'intermediate_sums.push(entry.join().unwrap());'

I've tried to google anything that could help, but still was stuck. I'm grateful for any help and pointers since this is the first time I'm coding in rust.

Can you post the exact error message? Also please put code between ```rust and ```.

2 Likes

Elaborating on the prior post, please read Forum Code Formatting and Syntax Highlighting and edit your initial post by using the pencil-shaped edit button under that post.

Many readers of this forum will ignore code snippets, compiler error reports, etc that do not follow the posting guidelines for new contributors that are pinned to the top of this forum. Even those who do respond may feel that the lack of following the forum posting guidelines is disrespectful of their time. Thanks. :clap:

1 Like

Sure Thanks for telling me!

Thank you! It was my mistake from the beginning that I couldn't seem to find the symbol on the keyboard... I ended up trying to use the ' single quotation mark and I didn't see anything happen, so I ended up removing them

(I'm assuming you meant vc.push(tt2).)
The problem is that vc is declared as a vector of usize:

let mut vc : Vec<usize> = Vec::new();

But tt2 is a std::thread::JoinHandle:

let tt2 = thread::spawn(move || {map_data(&p2)});

You can fix this by giving vc the correct type:

let mut vc: Vec<JoinHandle<_>> = Vec::new();

Or more easily by simply omitting the type and letting the compiler figure it out based on how it's used:

let mut vc = Vec::new();

You didn't paste the error message, but it's probably another symptom of the same problem. Since vc is declared as a Vec<usize>, the compiler thinks entry is a usize, not a JoinHandle.

1 Like

Seemed to fix both errors :laughing: Thank you so much!! I really appreciate your help!