Last active
January 17, 2017 20:33
-
-
Save Raztor0/08e09b987d6e5b08da7d754e4f5d5d4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface SomeClass : NSObject | |
@property (nonatomic, strong) NSDictionary *someDictionary; | |
@end | |
@implementation SomeClass | |
+ (void)load { | |
[self new]; | |
} | |
- (instancetype)init { | |
self = [super init]; | |
if (self) { | |
NSLock *lock; | |
lock = [NSLock new]; | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{ | |
NSLog(@"%@", [NSThread currentThread]); | |
while (true) { | |
@autoreleasepool { | |
int r = arc4random_uniform(2); | |
if (r % 2 == 0) { | |
self.someDictionary = nil; | |
} else { | |
NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary]; | |
for (int i = 0; i < 100; i++) { | |
[mutableDict setObject:@"hi" forKey:[[NSProcessInfo processInfo] globallyUniqueString]]; | |
} | |
[lock lock]; | |
self.someDictionary = mutableDict; | |
[lock unlock]; | |
} | |
} | |
} | |
}); | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), ^{ | |
NSLog(@"%@", [NSThread currentThread]); | |
while (true) { | |
@autoreleasepool { | |
[lock lock]; | |
NSDictionary *myDict = self.someDictionary; | |
/* This line will throw the exception: | |
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]' | |
*/ | |
NSArray __unused *keys = myDict.allKeys; | |
[lock unlock]; | |
} | |
} | |
}); | |
} | |
return self; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment