title: Sharing Mutable Variables Between Threads In Rust
body: <p><strong>Editor's note: This code example is from a version of Rust prior to 1.0 and is not syntactically valid Rust 1.0 code.</strong></p>
  
  <p>Is it possible to share a mutable variable between multiple threads in Rust? Given the following:</p>
  
  <pre><code>fn main() {
  
      let mut msg = "Hi";
      // ...
      msg = "Hello, World!";
  
      do spawn {
          println(msg);
      }
  
      do spawn {
          println(msg);
      }
  
  }
  </code></pre>
  
  <p>I get this error:</p>
  
  <p><img src="https://i.stack.imgur.com/yXXPC.png" alt="error"></p>
  
  <p>The variable just needs to be readonly to the spawned threads. The variable has to be mutable though, because what I'm really trying to do is share a HashMap between multiple threads. As far as I know there is no way to populate a HashMap unless it's mutable. Even if there is a way to do that though, I'm still interested in knowing how to accomplish something like this in general.</p>
  
  <p>Thank you!</p>