Assuming that you are @synthesizing the method implementations, atomic vs. non-atomic changes the generated code. If you are writing your own setter/getters, atomic/nonatomic/retain/assign/copy are merely advisory.
假设您是@ synzing方法实现,原子vs非原子更改生成的代码。如果您正在编写自己的setter/getter,那么原子/非原子/保留/分配/复制仅仅是咨询。
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. That is, if thread A is in the middle of the getter while thread B calls the setter, an actual viable value -- an autoreleased object, most likely -- will be returned to the caller in A.
对于原子,合成的setter/getter将确保所有值始终从getter中返回或由setter设置,而不考虑任何其他线程上的setter活动。也就是说,如果线程A位于getter的中间,而线程B调用setter,那么一个实际可行的值——最可能是一个autoreleated对象——将在A中返回给调用者。
In nonatomic, no such guarantees are made. Thus, nonatomic is considerably faster than atomic.
在非原子中,没有这样的保证。因此,非原子比原子快得多。
What atomic does not do is make any guarantees about thread safety. If thread A is calling the getter simultaneously with thread B and C calling the setter with different values, thread A may get any one of the three values returned -- the one prior to any setters being called or either of the values passed into the setters in B and C. Likewise, the object may end up with the value from B or C, no way to tell.
原子不做的是保证线程安全。如果线程与线程同时调用getter B和C调用setter与不同价值观,线程A可能会返回的三个值中的任何一个,前一个被调用setter或者值传递到setter的B和C .同样,价值的对象可能会从B或C,无法告诉。
Ensuring data integrity -- one of the primary challenges of multi-threaded programming -- is achieved by other means.
确保数据完整性(多线程编程的主要挑战之一)是通过其他方式实现的。