Objective-C properties are by default atomic, which ensures that accessors are atomic, but do not provide overall thread safety (like this question ). My question is that in most concurrency scenarios, there are no redundant atom properties? For instance:
Scenario 1: mutable properties
@interface ScaryMutableObject : NSObject {}
@property (atomic, readwrite) NSMutableArray *stuff;
@end
void doStuffWith(ScaryMutableObject *obj) {
[_someLock lock];
[obj.stuff addObject:something];
[_someLock unlock];
}
void doStuffWith(ScaryMutableObject *obj) {
NSMutableArray *cachedStuff = obj.stuff;
[_someLock lock];
[cachedStuff addObject:something];
[_someLock unlock];
}
Scenario 2: immutable properties
I thought that perhaps atomic properties would be useful for preventing locks when working with immutable objects, but since immutable objects can point to mutable objects in Objective-C, this doesn't help much:
@interface SlightlySaferObject : NSObject {}
@property (atomic, readwrite) NSArray *stuff;
@end
void doStuffWith(SlightlySaferObject *obj) {
[[obj.stuff objectAtIndex:0] mutateLikeCrazy];
}
, , (, , ), :
- ,
;
- ,
,
(,
a
NSString NSArray of
).
- ? ?