A simple question regarding multhreading programming: I have an NSMutableArray instance variable that is read by the main thread and set by another thread. I’m currently using this:
@property (nonatomic, retain) NSMutableArray *locations;
But I assume I have to remove the “nonatomic” directive now?
If you create a new array and assign it to locations then yes the atomic attribute would be needed.
If you are going to be adding/removing location objects from the other thread then the atomic attribute on the array does not apply. The various NSMutable… collections are not thread safe because the add/insert/remove methods are not designed to be called from multiple threads.
See SO question: NSMutableDictionary thread safety
A better approach might be to have the other thread send the main thread an array of locations to add or remove so that the changes only happen on the main thread.