title: Is this safe to call wait() of DispatchSemaphore several times at one time?
body: <p>I got three dispatched threads named queueA, queueB, queueC.<br />
  Now I want the queueA executed after queueB and queueC done.<br />
  So I tried to implement it by <code>DispatchSemaphore</code>.<br />
  <strong>My Problem is:</strong><br />
  Is this safe to call <code>wait()</code> two times in a thread at one time to make the semaphore 2?</p>
  <pre><code> self.semaphore.wait()  // -1
   self.semaphore.wait()  // -1
  </code></pre>
  <p>The  following is the entire test code:</p>
  <pre><code>class GCDLockTest {
      let semaphore = DispatchSemaphore(value: 0) 
     
      func test() {
          
          let queueA = DispatchQueue(label: &quot;Q1&quot;)
          let queueB = DispatchQueue(label: &quot;Q2&quot;)
          let queueC = DispatchQueue(label: &quot;Q3&quot;)
          queueA.async {
              self.semaphore.wait()  // -1
              self.semaphore.wait()  // -1
              print(&quot;QueueA gonna sleep&quot;)
              sleep(3)
              print(&quot;QueueA woke up&quot;)                
          }
          queueB.async {
              self.semaphore.signal()  // +1
              print(&quot;QueueB gonna sleep&quot;)
              sleep(3)
              print(&quot;QueueB woke up&quot;)
  
          }
          queueC.async {
              self.semaphore.signal()  // +1
              print(&quot;QueueC gonna sleep&quot;)
              sleep(3)
              print(&quot;QueueC wake up&quot;)
  
          }
      }
  }
  </code></pre>