zoukankan      html  css  js  c++  java
  • Dispatch Queues 线程池

    Dispatch Queues

    Dispatch queues are a C-based mechanism for executing custom tasks. A dispatch queue executes tasks either serially or concurrently but always in a first-in, first-out order. (In other words, a dispatch queue always dequeues and starts tasks in the same order in which they were added to the queue.) A serial dispatch queue runs only one task at a time, waiting until that task is complete before dequeuing and starting a new one. By contrast, a concurrent dispatch queue starts as many tasks as it can without waiting for already started tasks to finish. 

    Dispatch queues have other benefits: 

    • They provide a straightforward and simple programming interface.

    • They offer automatic and holistic thread pool management.

    • They provide the speed of tuned assembly. 

    • They are much more memory efficient (because thread stacks do not linger in application memory).

    • They do not trap to the kernel under load.

    • The asynchronous dispatching of tasks to a dispatch queue cannot deadlock the queue.

    • They scale gracefully under contention.

    • Serial dispatch queues offer a more efficient alternative to locks and other synchronization primitives.

    The tasks you submit to a dispatch queue must be encapsulated inside either a function or a block objectBlock objects are a C language feature introduced in OS X v10.6 and iOS 4.0 that are similar to function pointers conceptually, but have some additional benefits. Instead of defining blocks in their own lexical scope, you typically define blocks inside another function or method so that they can access other variables from that function or method. Blocks can also be moved out of their original scope and copied onto the heap, which is what happens when you submit them to a dispatch queue. All of these semantics make it possible to implement very dynamic tasks with relatively little code. 

    Dispatch queues are part of the Grand Central Dispatch technology and are part of the C runtime. For more information about using dispatch queues in your applications, see Dispatch Queues. For more information about blocks and their benefits, see Blocks Programming Topics

    https://developer.apple.com/library/content/documentation/General/Conceptual/ConcurrencyProgrammingGuide/ConcurrencyandApplicationDesign/ConcurrencyandApplicationDesign.html#//apple_ref/doc/uid/TP40008091-CH100-SW2

  • 相关阅读:
    Java_swing控件实例
    java_泛型 TreeSet 判断hashcode/length(升序排列)
    java_泛型(设置通配符下限)
    java_泛型(构造器)部分实例
    子类可以继承的同时实现接口
    继承类的线程写法
    匿名内部类的线程写法
    接口作为参数并用参数变量可以调用接口中的方法------------------需要多练习
    类可以作为参数类型,参数的变量还能调用作为参数类型的方法--------------需要多练习
    接口和类
  • 原文地址:https://www.cnblogs.com/feng9exe/p/8024611.html
Copyright © 2011-2022 走看看