title: Using NSCondition properly
body: <p>I was looking at the <a href="https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Multithreading/ThreadSafety/ThreadSafety.html" rel="nofollow">NSCondition documentation</a> examples and got a little confused:</p>
  
  <hr>
  
  <blockquote>
    <p>Whenever you use a condition object, the first step is to lock the
    condition. Locking the condition ensures that your predicate and task
    code are protected from interference by other threads using the same
    condition. Once you have completed your task, you can set other
    predicates or signal other conditions based on the needs of your code.
    You should always set predicates and signal conditions while holding
    the condition object’s lock.</p>
  </blockquote>
  
  <p>Listing 4-3  Using a Cocoa condition</p>
  
  <pre><code>[cocoaCondition lock];
  while (timeToDoWork &lt;= 0)
      [cocoaCondition wait];
  
  timeToDoWork--;
  
  // Do real work here.
  
  [cocoaCondition unlock];
  </code></pre>
  
  <p>Listing 4-4  Signaling a Cocoa condition</p>
  
  <pre><code>[cocoaCondition lock];
  timeToDoWork++;
  [cocoaCondition signal];
  [cocoaCondition unlock];
  </code></pre>
  
  <hr>
  
  <p>Let's say the thread using the Cocoa condition is blocking at <code>[cocoaCondition wait]</code>. Since <code>[cocoaCondition unlock]</code> has not been called yet, it also has ownership of the <code>cocoaCondition</code> lock.</p>
  
  <p>My question is--how does the condition ever get signaled? Once another thread tries to acquire the <code>cocoaCondition</code> lock, won't it block?</p>