title: Stop and start NSThread in Swift
body: <p>I have a thread with a <code>runLoop</code> inside thread's main function which is working right. This <code>runLoop</code> is inside a while loop which will iterate if cancelled is false. </p>
  
  <pre><code>public override func main() {
  
      super.main()
  
      var runLoop: NSRunLoop = NSRunLoop.currentRunLoop()
      do {
          runLoop.run()
      } while(!self.cancelled)
      NSLog("Thread stopped")
      NSThread.exit()
  }
  </code></pre>
  
  <p>When I set cancel flag to the thread (through <code>NSTreah.cancel()</code> method), the thread appears to successfully end, as I get <em>Thread stopped</em> in the console, but when I try to start the thread again I am always getting <code>attempt to start the thread again</code>. How can I restart the thread without getting this error?</p>