IOS three ways to work with threads

Source: Internet
Author: User

One, IOS implementation of threading methods are: Nsthread,cocoa nsoperation,gcd (Grand Central Dispatch) three kinds;

Nsthread its advantages: compared to the other two lightweight; disadvantage: the need to manage the thread life cycle, thread synchronization;

     cocoa Operation's advantages: Do not need to care about thread management, data synchronization of things, you can focus on the operation of their own needs to implement, the implementation of related classes Nsoperation,nsoperationqueue.

Grand Central Dispatch (GCD) is a solution for multi-core programming developed by Apple. Can only be used after the iOS4.0 has started. GCD is an efficient and powerful technique for replacing technologies such as Nsthread, Nsoperationqueue, nsinvocationoperation, etc.

Second, the thread implementation method introduction:

    nsthread . Span style= "Background-color:rgb (255,255,255); font-family:arial;line-height:26px;" > There are two ways to create them directly:

-(ID) Initwithtarget: (ID) target  selector: (SEL) selector  object: (ID) argument

+ (void) Detachnewthreadselector: (SEL) aselector  totarget: (ID) atarget  withobject: (ID) anargument

You can also use the NSObject class method  performselectorinbackground:withobject: Create a thread:

Thread Lock object: Circular lock Nsrecursivelock, conditional lock nsconditionlock, distributed lock Nsdistributedlock

Cocoa operation



This article from "Shenzhen Lian Cheng Tong technology Company" blog, reproduced please contact the author!

IOS three ways to work with threads

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.