title: Can I use a DispatchSemaphore to control a thread on main queue?
body: <p>Apparently I can only use DispatchSemaphore if I deal with different queues. But what if I want to run async code on the same queue (in this case the main queue).</p>
  
  <pre><code>let s = DispatchSemaphore(value : 0)
  DispatchQueue.main.async {
     s.signal()
  }
  s.wait()
  </code></pre>
  
  <p>This snippet doesn't work, because the async code is also waiting, because the semaphore blocked the main queue.
  Can I do this with semaphore? Or do I need to run the async code on a different queue?</p>
  
  <p>ps. I know I could use sync, instead of async and semaphore in this snippet. But This is just an example code to reproduce an async call.</p>