Skip to content

Instantly share code, notes, and snippets.

@nezhyborets
Created March 27, 2017 10:30
Show Gist options
  • Save nezhyborets/f0c4a31d77381a72c3e8c397a54907a7 to your computer and use it in GitHub Desktop.
Save nezhyborets/f0c4a31d77381a72c3e8c397a54907a7 to your computer and use it in GitHub Desktop.
AssignmentAtomicity
@implementation Test1 {
NSString *stringProp;
}
- (instancetype)init {
self = [super init];
if (self) {
[self test];
}
return self;
}
- (void)test {
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
dispatch_apply(10000000, dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^(size_t i) {
stringProp = [[NSString alloc] initWithFormat:@"%lu", i];
});
});
dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{
dispatch_apply(100000, dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^(size_t i) {
NSString *string = stringProp;
[self print:string];
});
});
}
- (void)print:(NSString * __unsafe_unretained)string {
NSLog(@"%@", string);
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment