4 ms·
This is in the context of properties in ObjC, which will synthesize accessor methods for the developer. If the property is marked `atomic` (which is also the de
by wool_gather 6y ago
This is in the context of properties in ObjC, which will synthesize accessor methods for the developer. If the property is marked `atomic` (which is also the default), the getter and setter will share a mutex. The mutex makes reads and writes effectively "atomic" -- gets and sets on different threads will never interrupt one another.
But that's all you get. And the catch is that there's usually more you need to do to guarantee thread safety for a particular operation.
For example, `@property (atomic) NSMutableArray *array;` has no guarantees about appending or removing the array's _contents_.
For another example `@property (atomic) NSUInteger count;` is a mildly subtle trap, because a statement like `self.count += 1;` is _not atomic_. It's an atomic read, an increment, and an atomic write. You need another synchronization mechanism to make the whole update threadsafe.