文章目录
题目
在@property (nonatomic, strong) NSString *name;
的情况下分别执行以下两段代码,会发生什么?
//Code 1
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
for (int i = 0; i < 1000; i++) {
dispatch_async(queue, ^{
self.name = [NSString stringWithFormat:@"abcdefghijk"];
});
}
//Code 2
dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
for (int i = 0; i < 1000; i++) {
dispatch_async(queue, ^{
self.name = [NSString stringWithFormat:@"abc"];
});
}
这里涉及的知识点有
- 多线程安全
- 属性修饰词的定义