title: Rust Lifetime Issue with Threads
body: <p>Here is the code:</p>
  
  <pre><code>use std::collections::HashMap;
  use std::thread;
  
  type MAP = HashMap&lt;String, String&gt;;
  
  fn handle_n_times(count: i32, map: &amp;mut MAP) {
      for i in 0..count {
          thread::spawn(move || {
              map.insert(format!("key-{}", i), format!("value-{}", i));
          });
      }
  }
  
  fn main() {
      let mut map: MAP = MAP::new();
      handle_n_times(5, &amp;mut map);
  }
  </code></pre>
  
  <p>I cannot compile:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0621]: explicit lifetime required in the type of `map`
   --&gt; src/main.rs:8:9
    |
  6 | fn handle_n_times(count: i32, map: &amp;mut MAP) {
    |                                    -------- help: add explicit lifetime `'static` to the type of `map`: `&amp;'static mut std::collections::HashMap&lt;std::string::String, std::string::String&gt;`
  7 |     for i in 0..count {
  8 |         thread::spawn(move || {
    |         ^^^^^^^^^^^^^ lifetime `'static` required
  </code></pre>
  
  <p>The hint it provides (add a <code>&amp;'static</code>) is not helpful.</p>
  
  <p><strong>Question 1</strong>: How to make this code work?</p>
  
  <p><strong>Question 2</strong>: After 1 solved, I want to use <code>std::sync::Arc</code> to make <code>map</code> thread-safe, what's the Rust way to do it?</p>