Atomic Properties

A nonatomic property setter might look like this:

// not-ARC, but ARC would be similar
- (void)setUserName:(NSString *)userName {
      if (userName != _userName) {
          [userName retain];
          [_userName release];
          _userName = userName;
      }
}
  • If you call this method concurrently, you might end up releasing _userName twice.

Atomic

  • Declaring a property as atomic results in implicit locking/unlocking around each access of this property.
  • Acquiring a lock on a resource always comes with a performance cost
  • Because acquiring and releasing a lock needs to be race-condition free,

results matching ""

    No results matching ""