title: Locking with Obj-C
body: <p>I'm really getting confused how locking works in Obj-C.</p>
  
  <p>I simply have a network request which I only want to call once at the same time. I want to block all other calls to it until it has received some data.</p>
  
  <p>My <code>lock</code> is of type <code>NSCondition</code> and static, <code>_sending</code> is just a bool. This is my implementation. The <code>getWithSuccess</code> is using <code>AFNetworking</code> for perform some action network requests, so I think it can start multiple threads or using some magic in GDC.</p>
  
  <p>My problem is that this implementation just give me deadlocks, and I need some hint how a correct implementation should work.</p>
  
  <pre><code>[lock lock];
  
  while (_sending)
      [lock wait];
  
  _sending = YES;
  
  [self getWithSuccess:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
      _sending = NO;
  
      [lock signal];
      [lock unlock];
  
  
  } fail:^() {
      _sending = NO;
  
      [lock signal];
      [lock unlock];
  }];
  </code></pre>