title: How do I share a mutable object between threads using Arc?
body: <p>I'm trying to share a mutable object between threads in Rust using <code>Arc</code>, but I get this error:</p>
  
  <pre class="lang-none prettyprint-override"><code>error[E0596]: cannot borrow data in a `&amp;` reference as mutable
    --&gt; src/main.rs:11:13
     |
  11 |             shared_stats_clone.add_stats();
     |             ^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
  </code></pre>
  
  <p>This is the sample code:</p>
  
  <pre><code>use std::{sync::Arc, thread};
  
  fn main() {
      let total_stats = Stats::new();
      let shared_stats = Arc::new(total_stats);
  
      let threads = 5;
      for _ in 0..threads {
          let mut shared_stats_clone = shared_stats.clone();
          thread::spawn(move || {
              shared_stats_clone.add_stats();
          });
      }
  }
  
  struct Stats {
      hello: u32,
  }
  
  impl Stats {
      pub fn new() -&gt; Stats {
          Stats { hello: 0 }
      }
  
      pub fn add_stats(&amp;mut self) {
          self.hello += 1;
      }
  }
  </code></pre>
  
  <p>What can I do?</p>