title: How to loop over thread handles and join if finished, within another loop?
body: <p>I have a program that creates threads in a loop, and also checks if they have finished and cleans them up if they have. See below for a minimal example:</p>
  <pre><code>use std::thread;
  
  fn main() {    
  
      let mut v = Vec::&lt;std::thread::JoinHandle&lt;()&gt;&gt;::new();
      for _ in 0..10 {
          let jh = thread::spawn(|| {
              thread::sleep(std::time::Duration::from_secs(1));
          });
          v.push(jh);
          for jh in v.iter_mut() {
              if jh.is_finished() {
                  jh.join().unwrap();
              }
          } 
      }
  }
  </code></pre>
  <p>This gives the error:</p>
  <pre><code>error[E0507]: cannot move out of `*jh` which is behind a mutable reference
      --&gt; src\main.rs:13:17
       |
  13   |                 jh.join().unwrap();
       |                 ^^^------
       |                 |  |
       |                 |  `*jh` moved due to this method call
       |                 move occurs because `*jh` has type `JoinHandle&lt;()&gt;`, which does not implement the `Copy` trait
       |
  note: this function takes ownership of the receiver `self`, which moves `*jh`
      --&gt; D:\rust\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\thread\mod.rs:1461:17
       |
  1461 |     pub fn join(self) -&gt; Result&lt;T&gt; {
  </code></pre>
  <p>How can I get the borrow checker to allow this?</p>