title: dispatch_semaphore_wait does not wait on semaphore
body: <p>I have developed the following method, which checks the app's ability to communicate with the server. 
  The method performs a simple query and knows that if it gets a result, the app should be connected (basic ping mechanism). </p>
  
  <pre><code>- (BOOL)isAppConnected
  {
      __block BOOL isConnected = NO;
  
      dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
  
      [[SFRestAPI sharedInstance] performSOQLQuery:@"SELECT id FROM Account LIMIT 1"
                                             failBlock:^(NSError *e) {
                                                 isConnected = NO;
                                                 NSLog(@"NOT CONNECTED %@", e);
                                                 NSLog(@"fail block ON THE MAIN THREAD? %hhd", [NSThread isMainThread]);
  
                                                 dispatch_semaphore_signal(semaphore);
  
                                             } completeBlock:^(NSDictionary *dict) {
                                                 isConnected = YES;
                                                 NSLog(@"%@", dict);
                                                 NSLog(@"complete block ON THE MAIN THREAD? %hhd", [NSThread isMainThread]);
  
                                                 dispatch_semaphore_signal(semaphore);
                                             }];
  
      // if the wait times-out we will receive a non-zero result and can assume no connection to SF
      //When using: DISPATCH_TIME_FOREVER the app hangs forever!!
      int waitResult = dispatch_semaphore_wait(semaphore, 30 * NSEC_PER_SEC); 
      NSLog(@"waitResult: %d", waitResult);
  
      return isConnected;
  }
  </code></pre>
  
  <p>I am using the 'dispatch_semaphore_wait' as suggested in the <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/Manpages/man3/dispatch_semaphore_wait.3.html" rel="nofollow">Apple documentation</a></p>
  
  <p>My goal is to wait on the response or a short timeout to figure out if we really have a valid connection. </p>
  
  <p>With the code above, 'dispatch_semaphore_wait' never actually waits, i.e. execution does not stop at that line but it continues immediately (always returning 49 as the result to the dispatch_semaphore_wait call). That is unless I use DISPATCH_TIME_FOREVER in which case the app hangs forever...</p>
  
  <p>At the moment I am calling this method from the main thread. I am aware that this is a bad idea, but I wanted to see this working as expected before refactoring. </p>
  
  <p>What could be causing this behaviour?
  Thanks.</p>