The difference between nonatomic and atomic? is atomic absolutely thread safe?

Source: Internet
Author: User

The difference between atomic and nonatomic is that the Getter/setter method generated automatically by the system is different. If you write Getter/setter yourself, that atomic/nonatomic/retain/assign/copy these keywords only prompts, write not to write all the same.

For atomic properties, the system-generated getter/setter guarantees the integrity of the get, set operation, and is unaffected by other threads. For example, thread A's getter method runs to half and thread B invokes the setter: then the getter of thread A can still get an object that is intact.

And nonatomic has no such guarantee. Therefore, the speed of nonatomic is faster than atomic.

However, atomic can not guarantee thread safety. If thread A has tuned the getter, meanwhile thread B and thread C have setter--the value of the last thread a get to, 3 kinds are possible: the original value before B, C set, or the value of B set or the value of C set. At the same time, the final value of this property may be the value of B set or the value of C set.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.