zoukankan      html  css  js  c++  java
  • iOS 中NSOperationQueue,Grand Central Dispatch , Thread的上下关系和区别

     In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations.

    In iOS 4 and later, operation queues use Grand Central Dispatch to execute operations.

    这2句话是NSOperationQueue Class Reference中的,这2句话表明NSOperationQueue是利用了GCD机制的,而Thread一直是最基本的多线程机制,那么它们3者的上下层关系便出来了:

    Thread最基本,其次是GCD,封装的最高层是operation quque。在遇到多线程问题时,推荐使用Operation Queue。最新的AFNetWorking库也使用Operation Queue代替了GCD,代码开起来更简洁了。

    那么这3中多线程方式具体的区别在哪里呢?

    首先说NSThread,这个是系统最基本的多线程机制,一切其他机制都是由它衍生出来的。既然是最基本的,那么用起来也一定最复杂:它仅仅提供了最基本的线程机制,不会提供那些同步异步的各种机制。

    其实,关键是区别CGD和NSOperationQueue 的区别。

     

  • 相关阅读:
    cin 与 getline
    ubuntu换源
    unbuntu 安装 bochs
    np.random.randint()的返回值
    vs2019 写入访问权限冲突
    44.Android之Shape设置虚线、圆角和渐变学习
    43.Android之ListView中BaseAdapter学习
    42.Android之ListView中ArrayAdapter简单学习
    Java编程思想学习(十六) 并发编程
    Java编程思想学习(十五) 注解
  • 原文地址:https://www.cnblogs.com/breezemist/p/3470822.html
Copyright © 2011-2022 走看看