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