Introduction to the Multi-threading 1-nsthread for iOS

Source: Internet
Author: User

On the importance of multithreading in iOS, no nonsense. Just one word: Important! ^_^

Three kinds of multithreading methods commonly used in iOS: Nsthread, GCD, nsopertaion

Although Nsthrea ranked first (almost all the books that introduce multithreading are so sorted), but with the least, reason: No back of the two younger brother with thoughtful.

As a multi-threaded eldest brother, Nsthread almost had to hide behind the scenes.

Nsthread is introduced from Mac OS to iOS, and before Mac OS 10.5, the Nsthread is enabled with only one:detachNewThreadSelector:toTarget:withObject:

After 10.5, Apple added a more minimalistic way to enable it: Start

And after 10.5, inheriting the subclass of the Nsthread, you can override the Main method (one of the thread's entry methods), no longer call Super's Main method;

Learn about Nsthrea outline:

1. Initialization

-(ID) init

This method is designed to initialize an instance,

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

Target: The object used to receive the message selector (in other words, the Select method that invokes target);

Selector: Message sent to target, (Target's selector method), this message can only have one parameter, and cannot have the return value;

Argument: An object passed to target, which can be nil;

Garbage collection mechanism has been a problem of Apple development, has been a long time iOS will also be considered OC is not garbage collection, in fact, this statement is not entirely correct; strictly speaking, OC under iOS is not garbage collected, under the Mac, OC has garbage collection mechanism;

In the absence of a garbage collection mechanism, the Selector method maintains an auto-free pool and puts the target and argument into the auto-release pool, releasing the auto-release pool when the thread exits;

In the case of a garbage collection mechanism, this automatic release pool will not be produced;

/***************************** Follow-up trailer ******************************

2. Use (START process/stop process/...)

3. Status query processing (whether main main thread/whether multi-threaded/Set priority/...)

4. Notifications (three notification messages)

***********************************************************************/

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.