I am quite new to multithreading programming and wonder if it is ok or to make a property like
@property BOOL shouldDoIt; //atomic
which will be used in a loop that is called in the background
- (void) loop{
// ... do stuff ...
if (self.shouldDoIt) {
[self doIt];
self.shouldDoIt = NO;
}
// ... do more stuff ...
}
and changed in a method called from the main thread
- (void) methodCalledFromMainThread{
self.shouldDoIt = YES;
}
Do I have to make it atomic or it does not change anything?
Я знаю, что atomic медленнее по сравнению с неатомарным, и моей программе нужно больше скорости, но если не использовать атомарный, то выполнение if (shouldDoIt) {
может не сработать?