Skip to content

Instantly share code, notes, and snippets.

@zhongge
Last active August 29, 2015 14:11
Show Gist options
  • Save zhongge/ad111629f238b67ff407 to your computer and use it in GitHub Desktop.
Save zhongge/ad111629f238b67ff407 to your computer and use it in GitHub Desktop.
What is difference between atomic and nonatomic properties?Which is default for synthesized properties?When would you use one vs. the others?
1. What is difference between atomic and nonatomic properties?
One of the primary challenges of multi-threaded programming.
Atomic properties are necessary in a reference counted multi threaded environment in order to stop objects from disappearing before a thread has a chance to retain them.
In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than "atomic".
2. Which is default for synthesized properties?
It is nonatomic.
With "atomic", the synthesized setter/getter will ensure that a whole value is always returned from the getter or set by the setter, regardless of setter activity on any other thread.
3. When would you use one vs. the others?
I have used the "atomic" for multi-threading. In general, i have used the nonatomic property.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment