title: How to terminate or suspend a Rust thread from another thread?
body: <blockquote>
    <p><strong>Editor's note</strong> — this example was created before Rust 1.0 and the specific types have changed or been removed since then. The general question and concept remains valid.</p>
  </blockquote>
  
  <p>I have spawned a thread with an infinite loop and timer inside. </p>
  
  <pre><code>thread::spawn(|| {
      let mut timer = Timer::new().unwrap();
      let periodic = timer.periodic(Duration::milliseconds(200));
      loop {
          periodic.recv();
  
          // Do my work here
      }
  });
  </code></pre>
  
  <p>After a time based on some conditions, I need to terminate this thread from another part of my program. In other words, I want to exit from the infinite loop. How can I do this correctly? Additionally, how could I to suspend this thread and resume it later?  </p>
  
  <p>I tried to use a global unsafe flag to break the loop, but I think this solution does not look nice.</p>