Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Wrapping network thread lazy initializer with dispatch_once, to ensur…

…e thread safety
  • Loading branch information...
commit a167217ee60a01235bf29792a46a4e8645a7835e 1 parent c0271e6
Mattt Thompson authored August 31, 2011

Showing 1 changed file with 4 additions and 2 deletions. Show diff stats Hide diff stats

  1. 6  AFNetworking/AFHTTPRequestOperation.m
6  AFNetworking/AFHTTPRequestOperation.m
@@ -108,10 +108,12 @@ @implementation AFHTTPRequestOperation
108 108
 static NSThread *_networkRequestThread = nil;
109 109
 
110 110
 + (NSThread *)networkRequestThread {
111  
-    if (!_networkRequestThread) {
  111
+    static dispatch_once_t oncePredicate;
  112
+    
  113
+    dispatch_once(&oncePredicate, ^{
112 114
         _networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil];
113 115
         [_networkRequestThread start];
114  
-    }
  116
+    });
115 117
         
116 118
     return _networkRequestThread;
117 119
 }

0 notes on commit a167217

Please sign in to comment.
Something went wrong with that request. Please try again.