title: How can I mutably share an i32 between threads?
body: <p>I'm new to Rust and threading and I'm trying to print out a number while adding to it in another thread. How can I accomplish this?</p>
  
  <pre><code>use std::thread;
  use std::time::Duration;
  
  fn main() {
      let mut num = 5;
      thread::spawn(move || {
          loop {
              num += 1;
              thread::sleep(Duration::from_secs(10));
          }
      });
      output(num);
  }
  
  fn output(num: i32) {
      loop {
          println!("{:?}", num);
          thread::sleep(Duration::from_secs(5));
      }
  }
  </code></pre>
  
  <p>The above code doesn't work: it always prints <code>5</code> as if the number is never incremented.</p>