title: Why are my Rust threads not running in parallel?
body: <p>I wish to spin up X threads which will fire X requests to the specified server within the code. Currently, my application is waiting for each thread and X requests to finish before spinning up the next one.</p>
  
  <p>How can I go about doing this async?</p>
  
  <pre><code>extern crate hyper;
  extern crate time;
  
  use hyper::header::Connection;
  use hyper::Client;
  use std::sync::{Arc, Mutex};
  use std::thread;
  use time::*;
  
  struct Request {
      elapsed_time: f64,
  }
  
  impl Request {
      fn new(elapsed_time: f64) -&gt; Request {
          Request {
              elapsed_time: elapsed_time,
          }
      }
  }
  
  fn main() {
      let requests = Arc::new(Mutex::new(Vec::new()));
  
      for _x in 0..100 {
          println!("Spinning up thread...");
  
          let mut client = Client::new();
          let thread_items = requests.clone();
  
          let handle = thread::spawn(move || {
              for _x in 0..100 {
                  println!("Firing the request");
                  let start = time::precise_time_s();
  
                  let _res = client
                      .get("http://jacob.uk.com")
                      .header(Connection::close())
                      .send()
                      .unwrap();
  
                  let end = time::precise_time_s();
  
                  thread_items
                      .lock()
                      .unwrap()
                      .push((Request::new(end - start)));
              }
          });
  
          handle.join().unwrap();
      }
  }
  </code></pre>
  
  <p>Program output:</p>
  
  <pre class="lang-none prettyprint-override"><code>Spinning up thread...
  Firing request
  Firing request
  Firing request
  Firing request
  Spinning up thread...
  Firing request
  Firing request
  Firing request
  Firing request
  Spinning up thread...
  Firing request
  Firing request
  Firing request
  Firing request
  </code></pre>