Skip to content

Commit

Permalink
Wrapping network thread lazy initializer with dispatch_once, to ensur…
Browse files Browse the repository at this point in the history
…e thread safety
  • Loading branch information
mattt committed Aug 31, 2011
1 parent c0271e6 commit a167217
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions AFNetworking/AFHTTPRequestOperation.m
Expand Up @@ -108,10 +108,12 @@ @implementation AFHTTPRequestOperation
static NSThread *_networkRequestThread = nil; static NSThread *_networkRequestThread = nil;


+ (NSThread *)networkRequestThread { + (NSThread *)networkRequestThread {
if (!_networkRequestThread) { static dispatch_once_t oncePredicate;

dispatch_once(&oncePredicate, ^{
_networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil]; _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil];
[_networkRequestThread start]; [_networkRequestThread start];
} });


return _networkRequestThread; return _networkRequestThread;
} }
Expand Down

0 comments on commit a167217

Please sign in to comment.