Atomic and non-atomic properties, mutex and spin lock introduction

Source: Internet
Author: User

Nonatomic non-atomic properties are non-thread safe, suitable for small memory mobile devices (mobile phones, tablets ...)

Atomic Atomic properties (thread safe, but requires a lot of resources) designed for multithreading, the default is to ensure that only one thread can write at the same time, which is itself a spin lock; write multiple read, single thread write, multiple threads read

Note: When you override the Get and set methods of a property, you need to add it after @implementation: @synthesiae Property Name = _ Property name;

Mutual exclusion lock vs. spin lock

Mutex: If another thread is found to be executing the lock code, the thread goes into hibernation (ready state), and the thread wakes (executes) after the other thread has opened the lock.

Spin lock: If another thread is found to be locking code, the thread will wait until the locked code is executed in a dead loop, and the spin lock is more suitable for executing the code;

Note: Almost all classes provided by Uikit are thread insecure, and all UI update operations are performed on the main thread

Atomic and non-atomic properties, mutex and spin lock introduction

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.