The difference between objective-c:atomic and nonatomic

Source: Internet
Author: User

The difference between atomic and nonatomic:


Atomic: When setting the @property property of a member variable, the default is atomic, which provides multithreading security. Because of multithreading, all objects in the operation of the member variables are synchronous, so, in order to prevent an object in the operation of data is not finished by another object snatched by the tampering,atomic for this provides a multi-threaded security mechanism, the use of synchronous locking method to control the process of ownership. That is: {lock}//The first object gets the operation data, locks its own process, others can not be robbed before I release the lock.
if (Property! = newvalue) {
[Property release];
property = [NewValue retain];
}
{unlock}//After the object has finished manipulating the data, the synchronization lock is released, and someone else can get the data to do their own work. Description: The lock must be unique.nonatomic:When setting the @property property of a member variable, set Nonatomic to prohibit multithreading. This directly eliminates the possibility of tampering by the other side of the data operation. This setting is generally used if it is not multi-threaded.

The difference between objective-c:atomic and nonatomic

Related Article

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.