What does the property “Nonatomic” mean?

后端 未结 9 698
野趣味
野趣味 2020-12-04 05:16

What does \"nonatomic\" mean in this code?

@property(nonatomic, retain) UITextField *theUsersName;

What is the difference between atomic an

相关标签:
9条回答
  • 2020-12-04 05:43

    If you specify "atomic", the generated access functions have some extra code to guard against simultaneous updates.

    0 讨论(0)
  • 2020-12-04 05:45

    In addition to what's already been said about threadsafeness, non-atomic properties are faster than atomic accessors. It's not something you usually need to worry about, but keep it in mind. Core Data generated properties are nonatomic partially for this reason.

    0 讨论(0)
  • 2020-12-04 05:47

    In a multi-threaded program, an atomic operation cannot be interrupted partially through, whereas nonatomic operations can.

    Therefore, you should use mutexes (or something like that) if you have a critical operation that is nonatomic that you don't want interrupted.

    0 讨论(0)
  • 2020-12-04 05:51

    The "atomic” means that access to the property is thread-safe. while the "nonatomic" is the opposite of it. When you declare a property in Objective-C the property are atomic by default so that synthesized accessors provide robust access to property in a multithreaded environment—that is, the value returned from the getter or set via the setter is always fully retrieved or set regardless of what other threads are executing concurrently. But if you declare property as nonatomic like below

    @property (nonatomic, retain)  NSString *myString;
    

    then it means a synthesized accessor for an object property simply returns the value directly. The effect of the nonatomic attribute depends on the environment. By default, synthesized accessors are atomic. So nonatomic is considerably faster than atomic.

    0 讨论(0)
  • 2020-12-04 05:55

    You can able to get a handle of this stuffs by reading the below article.

    Threading Explained with the nonatomic's purpose

    nonatomic - Not Thread Safe

    atomic - Thread Safe - This is the default property attribute.

    0 讨论(0)
  • 2020-12-04 05:59

    Usually atomic means that writes/reads to the property happen as a single operation. Atomic_operation

    0 讨论(0)
提交回复
热议问题