IOS: Multithreaded Nsthread for detailed use

Source: Internet
Author: User

Nsthread specific use: Direct inheritance NSObject


nsthread:.Pros: Nsthread is lightweight and easy to useCons: You need to manage your thread's lifecycle and thread synchronization. Thread synchronization has a certain overhead in locking data 1. Properties@property (ReadOnly, retain) nsmutabledictionary *threaddictionary; //Threading Dictionary @property double threadpriority; //Thread Priority @property nsqualityofservice qualityofservice; //Quality of service @property (copy) nsstring *name; //thread name @property Nsuinteger stackSize; //Stack size @property (readonly) BOOL ismainthread; //is the main thread@property (readonly, getter=isexecuting) BOOL executing; //Whether the thread is executing @property (readonly, getter=isfinished) BOOL finished; //Thread execution complete @property (readonly, getter=iscancelled) BOOL cancelled; //Whether the thread is canceled 2. Notice will be a multi-threaded notification
foundation_export NSString * Const nswillbecomemultithreadednotification;             has become a single-threaded notificationfoundation_export NSString * Const nsdidbecomesinglethreadednotification;            notification that the thread will exitfoundation_export NSString * Const nsthreadwillexitnotification; 3. Main methods※ Current Thread+ (Nsthread *) CurrentThread;※ Create a thread's class method and add an execution event

+ (void) Detachnewthreadselector: (SEL) selector totarget: (ID) target withobject: (id) argument;

※ Whether it is multi-threading

+ (BOOL) ismultithreaded;

※ Timed Sleep

+ (void) Sleepuntildate: (NSDate *) date;

※ Sleep Time

+ (void) Sleepfortimeinterval: (Nstimeinterval) ti;

※ Exit Thread

+ (void) exit;

※ Thread Priority

+ (double) threadpriority;

※ Set Thread priority

+ (BOOL) SetThreadPriority: (double) p;

※ Displays the current stack contents (returns an array of the addresses that the thread occupies in the stack)

+ (Nsarray *) callstackreturnaddresses;

※ Return the symbol of the stack space

+ (Nsarray *) Callstacksymbols;

※ is the main thread

+ (BOOL) ismainthread;

※ Create an instance method of the thread and add an execution event

-(Instancetype) Initwithtarget: (ID) Target selector: (SEL) Selector object: (id) argument;

※ Cancel Thread

-(void) cancel;

※ Start Thread

-(void) start;

※ Thread body to execute the method: Thread Body method

-(void) main;

 4, Category: @interface nsobject (nsthreadperformadditions)    

※ Call the main thread to update the UI

-(void) Performselectoronmainthread: (SEL) Aselector withobject: (ID) arg waituntildone: (BOOL) Wait modes: (Nsarray *) Array

※ Calling the main thread

-(void) Performselectoronmainthread: (SEL) Aselector withobject: (ID) arg waituntildone: (BOOL) wait;

※ Call the specified thread to update the data

-(void) Performselector: (SEL) aselector onthread: (Nsthread *) THR Withobject: (ID) arg waituntildone: (BOOL) wait modes: ( Nsarray *) array;

※ Call the specified thread

-(void) Performselector: (SEL) aselector onthread: (Nsthread *) THR Withobject: (ID) arg waituntildone: (BOOL) wait;

※ threads are called in the background

-(void) Performselectorinbackground: (SEL) Aselector withobject: (ID) arg;  

IOS: Multithreaded Nsthread for detailed use

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.