diff --git a/Classes/SBJsonStreamParserState.m b/Classes/SBJsonStreamParserState.m index f0cd74a6..42981ad9 100644 --- a/Classes/SBJsonStreamParserState.m +++ b/Classes/SBJsonStreamParserState.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; \ } diff --git a/Classes/SBJsonStreamWriterState.m b/Classes/SBJsonStreamWriterState.m index 9f04cac4..8eb47f36 100644 --- a/Classes/SBJsonStreamWriterState.m +++ b/Classes/SBJsonStreamWriterState.m @@ -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; \ }