title: Starting and Stopping Ruby Threads
body: <p>How would I Start and stop a separate thread from within another thread?</p>
  
  <pre><code>loop_a_stopped = true
  loop_a = Thread.new do
      loop do
          Thread.stop if loop_a_stopped
  
          # Do stuff
  
          sleep 3
      end
  end
  
  loop_b = Thread.new do
      loop do
          response = ask("&gt; ")
          case response.strip.downcase
              when "start"
                  loop_a_stopped = false
                  loop_a.run
              when "stop"
                  loop_a_stopped = true
              when "exit"
                  break
          end
      end
  end
  
  loop_a.join
  loop_b.join
  </code></pre>