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