From a167217ee60a01235bf29792a46a4e8645a7835e Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 31 Aug 2011 09:59:34 -0500 Subject: [PATCH] Wrapping network thread lazy initializer with dispatch_once, to ensure thread safety --- AFNetworking/AFHTTPRequestOperation.m | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 1ad535c..23695cb 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -108,10 +108,12 @@ static inline BOOL AFHTTPOperationStateTransitionIsValid(AFHTTPOperationState fr static NSThread *_networkRequestThread = nil; + (NSThread *)networkRequestThread { - if (!_networkRequestThread) { + static dispatch_once_t oncePredicate; + + dispatch_once(&oncePredicate, ^{ _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil]; [_networkRequestThread start]; - } + }); return _networkRequestThread; }