Permalink
Browse files

Merge pull request #140 from AlenZhou/master

Make SINGLETON thread safe
  • Loading branch information...
2 parents cbdf88a + 6ee1724 commit 8e0d32c31857e5627ed059e5a759cec60985edbe @stig committed Jul 31, 2012
Showing with 11 additions and 3 deletions.
  1. +5 −1 Classes/SBJsonStreamParserState.m
  2. +6 −2 Classes/SBJsonStreamWriterState.m
@@ -36,7 +36,11 @@
#define SINGLETON \
+ (id)sharedInstance { \
static id state = nil; \
- if (!state) state = [[self alloc] init]; \
+ if (!state) { \
+ @synchronized(self) { \
+ if (!state) state = [[self alloc] init]; \
+ } \
+ } \
return state; \
}
@@ -35,8 +35,12 @@
#define SINGLETON \
+ (id)sharedInstance { \
- static id state; \
- if (!state) state = [[self alloc] init]; \
+ static id state = nil; \
+ if (!state) { \
+ @synchronized(self) { \
+ if (!state) state = [[self alloc] init]; \
+ } \
+ } \
return state; \
}

0 comments on commit 8e0d32c

Please sign in to comment.