The four diagrams of iOS development show the Test source code attached to the GCD (Grand Central Dispatch ).

Source: Internet
Author: User

First, introduce several concepts: GCD, queue, serial, parallel, synchronous, asynchronous.

GCD (Grand Central Dispatch ):

The Great Apple developed a multi-core multi-thread solution.

    • Is a C language-based underlying API
    • Defining tasks with blocks is flexible and convenient to use.
    • Provides more control capabilities and underlying functions not available in the Operation queue

The basic idea of GCD is to put the operation s in the queue s for execution.

  • Use Blocks to define the operation
  • The thread where the queue is responsible for scheduling task execution and the specific execution time
  • The queue is characterized by first-in-first-out (FIFO). Newly Added to the column will be placed at the end of the team.
  • All GCD functions start with dispatch (dispatch and scheduling ).

Queue (FIFO ):

The queue is an advanced, first-in-first-out organization. The most funny and vivid explanation I have seen is: (the difference between the queue and the stack is that if you pull too much, the queue is consumed too much and the stack is consumed too much ).

  • In the serial queue, tasks in the queue are only executed sequentially.
  • Parallel queue. Tasks in the queue are usually executed concurrently.

If the concept of "serial" and "Parallel" is unclear, I would like to give another example: 10 people have bought things in the supermarket and checked out in line at a cash register, the previous checkout operation is not completed, and the last one has to wait. This is a typical serial. 10 people go to 10 different cashier points to check the account at the same time. This is parallel. For more information, see the following example.

Synchronous and asynchronous (for more details, refer to the encyclopedia)

  • Asynchronous operations (dispatch_async) are executed concurrently, and the execution sequence of tasks cannot be determined.
  • The synchronization operation (dispatch_sync) is executed in sequence and can determine the execution sequence of tasks.

See the following four images:

 

 

 

 

 

 

 

 

 

 

 

 

 

Note: In parallel queues, the location of asynchronous tasks is meaningless. That is, asynchronous tasks are executed concurrently no matter where they are not placed!

Test source link: http://pan.baidu.com/s/1bnCd8HT

The above is purely personal understanding and has a limited level. If you have any mistakes, please try it!

Related Article

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.