Atomic vs. nonatomic

Source: Internet
Author: User

Declaring a property atomic makes compiler generate additional code this prevents concurrent access to the property. This additional code locks a semaphore, then gets or sets the property, and then unlock the semaphore. Compared to setting or getting a primitive value or a pointer, locking and unlocking a semaphore is expensive (although it is usually negligible if you consider the overall flow of your app). and also the property atomic doesn ' t mean thread safety. The property, read by one, thread for mutiple times, different when it's modifing by another thread. The thread safety is garanteed by a more complicate mechanism.

Since of your classes under IOS, especially the ones related to UI, would be used in a single-threaded environment, it is safe to drop atomic (i.e. write nonatomic , because properties was by atomic default): Even though the operation is Relativel Y inexpensive, you don't want to pay for things that's do not need.

Reference:

Http://stackoverflow.com/questions/588866/whats-the-difference-between-the-atomic-and-nonatomic-attributes

Http://stackoverflow.com/questions/17571338/why-properties-are-always-said-to-be-made-nonatomic-in-objective-c

Atomic vs. nonatomic

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.