iOS under lock using-09-Multithreading

Source: Internet
Author: User


iOS under lock use time:2014-08-08 15:36:56

Summarize what I know about the lock under iOS:

1. Mutual exclusion Lock

@synchronized, @synchronized block implicitly adds an exception-handling routine to protect the code. The processing routine releases the mutex automatically when the exception is thrown. This means that in order to use the @synchronized directive, you must enable exception handling in your code.

Nslock

Nsrecursivelock, recursive lock, can be used multiple times in a thread

Nsconditionlock, conditional lock, in fact, is also a mutex, similar to nscondition, but nscondition wait is awakened, may not really meet the conditions, need to check, for example:

[cocoaConditionlock];while (timeToDoWork <=0)    [cocoaConditionwait]; timeToDoWork--;

Spin lock is also an exclusive lock

Dispatch once can also be regarded as an exclusive lock, its efficiency is quite high; I read an article with a basic understanding, do not use memory barrier, mainly using branch prediction method, used to prompt the branch prediction errors before, to achieve the effect; it's more interesting. One problem is whether the dispatch once can be used as an exclusive execution of some blocks, and if efficiency is better

2. Signal Volume

DISPATCH_SEMAPHORE,GCD, but did not find POSIX and Mach, POSIX should be able to use, Mach is said to be a kernel-state

3. Spin Lock

Osspinlocklock

4. Read/write Lock

POSIX read-write Lock: refer to Https://github.com/otium/OTMRWLock

5. Distributed lock

Distributed lock (distributed lock) process-level locks that only report status and do not block processes. Nsdistributedlock is implemented using a file system. I don't have a concept at all.

No lock synchronization

1. Atomic variables

Atomic variables, that is, send FSB lock bus, hardware lock

Type __sync_fetch_and_add (type *ptr, type value);
Type __sync_fetch_and_sub (type *ptr, type value);
Type __sync_fetch_and_or (type *ptr, type value);
Type __sync_fetch_and_and (type *ptr, type value);
Type __sync_fetch_and_xor (type *ptr, type value);
Type __sync_fetch_and_nand (type *ptr, type value);
Type __sync_add_and_fetch (type *ptr, type value);
Type __sync_sub_and_fetch (type *ptr, type value);
Type __sync_or_and_fetch (type *ptr, type value);
Type __sync_and_and_fetch (type *ptr, type value);
Type __sync_xor_and_fetch (type *ptr, type value);
Type __sync_nand_and_fetch (type *ptr, type value);

This iOS also has a corresponding function, such as OSAtomicIncrement32, which is relatively efficient.

2. CAS

CAS is really lock-free, __sync_bool_compare_and_swap, thread-safe

iOS under lock use, Bubu buckle, bubuko.com

iOS under lock use

Tags: class code problem file using COM HTTP thread

comments (0) >> More comments Click here to comment Week Hottest tags more log class com style http use si it src la code sp HTML file Java Problem data des method ha for as CA io android BS algorithm Go t P an IM time ad c target word on transaction EF JS TR Linux Server C + + Learn AI UI res sql iOS work 00 Android 64 database Static nbsp Program function ext Share archive more March 09, 2015 (980)
March 08, 2015 (1337)
March 07, 2015 (1415)
March 06, 2015 (2105)
March 05, 2015 (2256)
March 04, 2015 (2078)
March 03, 2015 (1929)
March 02, 2015 (2015)
March 01, 2015 (1190)
February 28, 2015 (1760) weekly ranking more
  • An easy way to install Kali-linux under Android 2014-09-21
  • Mobile Web page front end Development summary 2014-07-29
  • App backend Design (--im4java+graphicsmagick) realizes Chinese watermark 2015-01-16
  • "Android Interface Implementation" Slidingmenu the latest version of the use of detailed 2014-10-22
  • "iOS Dev-27" solution: An error is encountered while running (Domain=fbsopenapplicationerrordomain, code=4) 2014-10-01
  • Use UE4 to publish Android platform games 2014-07-15
  • Android Tips your project contains error (s), please fix them before running your application 2014-05-10
  • Android for dual process daemon 2014-11-18
  • Android Gson parsing Multi-layered nested complex data 2014-08-06
  • Swipe.js easy to achieve mobile phone-side sliding effect 2014-11-19
Friendship link Country painting cnbeta CSDN Blog Park it168 Baidu statistics Webmaster Statistics Yang and mobile development       Baidu Cloud AccelerationAbout Us-Contact us © © No. 09046678 bubuko.com All rights reserved-4Open the Technology button, share the program life! ↑↓

iOS under lock using-09-Multithreading

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.