Ios_ Multithreading _GCD

Source: Internet
Author: User

1. GCD Serial Queue + Asynchronous Dispatch Description:Very very , very useful operationAsynchronous, indicating that a new thread will be opened outside the main thread, but because the queue is serial, it only opensOne (open one only)New thread when the dispatch is assigned a block, the main thread returns immediately, continuing to execute the serial queue down, indicating that the blocks assigned to this queue will be sequentially executed one after the other.Dispatch_async Description:return immediately, never wait, queue determines whether it is serially or concurrently,block_copy (), Block_release ()

program run result output:you can see: Serial queue + asynchronously adds block to the queue,only a new thread will be opened, and all the added blocks are executed in a happy and orderly manner in the newly opened thread .

2, GCD serial queue + synchronous dispatch (rarely used)synchronous means: No new threads are opened, run on main threadserial representation: All blocks run one after another



3. Parallel Queue + Asynchronous dispatch (easy to get out of control)

Open multiple new Threads ( with few controls ), block execution is not sequential , Programmer cannot control execution order



4. Concurrent Queue + Synchronous dispatch

Key : Because of synchronization, no new threads are opened and the main thread is used directly ,

Although it is a concurrent queue, because there can be one execution route , it is executed sequentially




5, Divergent thinking---> Serial queue first sync dispatch 10 blocks, then asynchronously dispatch 10 blockssince it is a synchronous dispatch: It is executed on the main thread and, after completion,Asynchronous Dispatch: Open a new thread, because the queue is serial, it will only open a new thread, one by one happily executed


6, divergent thinking---> Parallel queue, the first synchronous allocation of 10 blocks, and then asynchronously dispatched 10 Blcokas long as the dispatch is synchronous, it will only run on the main thread.The asynchronous dispatch, will certainly open a new thread, because it is a parallel queue: it will open n new threads, n number is not controllable, block execution order is not controllable















Ios_ Multithreading _GCD

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.