Browse Source

GCD方式创建单例 fix #2

gaosboy 12 years ago
parent
commit
42d7d6882f
1 changed files with 4 additions and 4 deletions
  1. 4 4
      Kache/Kache.m

+ 4 - 4
Kache/Kache.m

@@ -33,11 +33,11 @@
 #pragma mark static for default
 #pragma mark static for default
 
 
 + (Kache *)instance {
 + (Kache *)instance {
-    static Kache *obj = nil;
-    if (nil == obj) {
+    static dispatch_once_t once_token;
+    static Kache *obj= nil;
+    dispatch_once(&once_token, ^{
         obj = [[Kache alloc] init];
         obj = [[Kache alloc] init];
-    }
-    
+    });
     return obj;
     return obj;
 }
 }