What I have tried:
@property (nonatomic, assign) int count;
in global queue:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
for (int i = 0; i < 10000; i ++) {
self.count ++;
}
});
in main queue:
for (int i = 0; i < 10000; i ++) {
self.count ++;
}
After these operations finished, the log shows count value is below 20000. because of Data Race (Xcode point it out).
Then I change property from nonatomic
to atomic
, value still below 20000, without Data Race (Xcode didn't point it out)
So , I have some questions about atomic
, which case should we use atomic
? which is the best way to use atomic
?