No more deceptive! Nsoperation is the recommended multithreading technology for Apple!

Source: Internet
Author: User

First of all, small soup I in the actual development, actually also like to use gcd a bit more, because it feels more convenient to use.
But what is the truth?
Apple recommended to use is actually nsoperation, so hope that no research on this people don't mislead others in the blog ah.
In other words, the objective-c language used by Apple for development is object-oriented, how can she recommend that you use C-based process-oriented development? (This sentence is only spit groove, do not spray ...)

About Nsoperation

Many people, when talking about nsoperation in the blog, will take 它是iOS2.0推出的 this point to emphasize that later iOS4.0 launched GCD is the recommended use of multi-threaded use of apple!
For this, I do not think that all blame them, because a lot of people in the development of the study through the information to learn, very few would like to see Apple given 官方文档 .
In fact, Apple in the official document on this has been specifically described, Nsoperation is indeed iOS2.0 launched, at that time the nsoperation is achieved through nsthread, the efficiency is indeed general, but!!

苹果在iOS4.0推出GCD之后,又重写了NSOperation,从此以后,NSOperation的底层就是由GCD实现的了!!

Here is the original text of the official document:

(Operation queues usually provide the threads used toRun their operations.inchOS X V10.6  andLater, operation queues use the LibdispatchLibrary(also known asGrand Central Dispatch) toInitiate the execution oftheir operations. asAresult, operations is always executed onA separate thread, regardless ofWhether they is designated asConcurrentorNon-concurrent operations.inchOS X V10.5, however, operations is executed onSeparate threads onlyifTheir isconcurrent Method returns NO. If  that Method returns YES,  the operation object  is expected  to Create  its own Thread (or start some asynchronous operation);The queue does notProvide a thread forit.)
Comparison of Nsoperation and GCD:
    1. First of all, the life cycle of their threads is automatically managed relative to Nsthread or cross-platform pthread, and developers have no need to write any thread-managed code as long as they are concerned about what to do
    2. GCD is an Apple solution for multi-core parallel computing that automatically leverages more CPU cores (such as dual-core, quad-core), while Nsoperation is a GCD-based object-oriented package with GCD features.
    3. GCD provides some features that the nsoperation does not have:

      1) 一次性执行2) 延迟执行 3) 调度组
    4. GCD is a function that adds a task (block) to a queue (serial/parallel/global/Home column) and performs a task synchronously/asynchronously, while Nsoperation adds an operation (typically an asynchronous task) to a queue (typically a concurrent queue) and performs a function that specifies the operation.

    5. The nsoperation provides some handy operations:

      1) 最大并发数2) 队列的暂定/继续3) 取消所有的操作4) 指定操作之间的依赖关系(GCD可以用同步实现)

      Among them, about the maximum concurrency of this one, Apple recommended the use of nsoperation another strong evidence.
      Because, in contrast to the case where Apple previously limited the maximum number of concurrent threads,

        苹果不再限制线程的最大并发数。

That is, this is bad for using GCD development because GCD cannot control the maximum number of concurrent threads, and the number of concurrent threads is excessive ... You know ~

So, on top of that, Apple actually recommends that we use nsoperation in the development process, not gcd! Also ask you to pay attention in the development of OH ~

No more deceptive! Nsoperation is the recommended multithreading technology for Apple!

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.