IOS multi-thread NSThread

Source: Internet
Author: User

Thread NSThread Multithreading

 

Threads and processes
Process
Is an active program, a container
Is the minimum unit for system resource management.
High switching cost

Thread
Is the code that runs in the process container and actually works
Is the minimum unit of program execution.
Low switching cost (because the thread is switching in the same memory)

An NSThread object controls a thread in a program. When you have many tasks to execute but do not want to block the main thread,
Multithreading is useful. Multiple Threads can be used to execute multiple tasks at the same time.

NSThread Method
// Initialization
1.-(id) init // This is the specified Initialization Method of NSThread
2.-(id) initWithTarget :( id) target selector :( SEL) selector object :( id) argument
When initializing a thread, it should be noted that this SEL can only have one parameter, and the method selected cannot have a return value,
Note that this method only creates a thread and does not start the thread. Use the stat method to start the thread.

3. + (void) detachNewThreadSelector :( SEL) aSelector toTarget :( id) aTarget withObject :( id) anArgument
Create and start a thread.
4.-(void) start // start a thread
5. + (void) sleepUntilDate :( NSDate *) aDate
Blocks the current thread until the specified time
6. + (void) sleepForTimeInterval :( NSTimeInterval) ti
Sleep a thread for a period of time

// Determine the thread status
7.-(BOOL) isExecuting // determine whether the thread is being executed
8.-(BOOL) isCancelled // determine whether the thread has been canceled
9.-(BOOL) isFinished // determine whether the thread has completed execution
10. + (BOOL) isMainThread // determine whether the current thread is the main thread
11. + (BOOL) isMultiThreaded // determine whether the application is multi-threaded.
12.-(BOOL) isMainThread // determine whether the specified object is the main thread.


13. + (NSThread *) mainThread // returns a main thread object
14. + (NSThread *) currentThread // returns the current thread
15. + (NSArray *) callStackReturnAddresses
The returned result is an array composed of the addresses occupied by the thread in the stack.
16. + (NSArray *) callStackSymbols // return the symbol of the stack space

 

// Thread attributes

17.-threadDictionary // Dictionary of the returned thread object
18.-name // return the thread name
19.-setName: // set the thread name
20.-stackSize // the size of the stack occupied by the return thread
21.-setStackSize: // set the size of the stack occupied by the thread


// Thread priority
22. + threadPriority // returns the priority of the current thread. In fact, a double number is returned,
// From 0.0 to 1.0, of which 1.0 is the highest
23.-threadPriority // returns the priority of the current thread object
24. + setThreadPriority: // sets the limited permission of the current thread.

25.-setThreadPriority: // same as above

 

 




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.