Parsing locks in objective-C

Source: Internet
Author: User

In iOS development, nslock is commonly used to achieve simple mutual exclusion. Nslock operations include lock, unlock, trylock, and lockbeforedate. Therefore, the so-called lock and unlock are simple thread locks. trylock and lockbeforedate are two methods implemented by IOS without blocking threads.

Trylock does not block the thread. If the lock fails, no is returned;

Lockbeforedate is used to determine when to unlock the data.


The nsrecurisvelock, nscoditionlock, and nsdistributelock are recursive locks in IOS.


Recursive lock nsrecurisvelock: it is usually used in recursion and does not cause thread blocking. However, the lock and unlock must be paired.


Conditional lock nscoditionlock: You can pass in a public variable as a condition to synchronize data at different thread times.


Distribution lock nsdistributelock: Used as the lock condition for files, which can be accessed between different processes to achieve process synchronization.


In addition, @ synchronize can be used in IOS to achieve thread mutex. The objc object can be used as a token between different threads.

Parsing locks in objective-C

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.