Created
March 27, 2017 10:30
-
-
Save nezhyborets/f0c4a31d77381a72c3e8c397a54907a7 to your computer and use it in GitHub Desktop.
AssignmentAtomicity
This file contains hidden or 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
@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