GCD Multithreading Notes

1. The difference between serial and parallel queues

    Serial Dispatch Queue : Serial queue, waiting for the end of the currently executing processing

    Concurrent Dispatch Queue : Parallel queue, do not wait for the current processing to end

2. The difference between synchronous and asynchronous dispatch

    dispatch_async : Asynchronously, append the specified Block to the specified Dispatch Queue "asynchronously". The dispatch_async function does not wait for processing execution to end.

    dispatch_sync : Synchronously, append the specified Block to the specified Dispatch Queue "synchronously". The dispatch_sync function waits for the processing execution to end.

3. Combination of distribution method and specified queue type

    Synchronous dispatch to serial queue: no new thread is started, tasks are executed in sequence, blocking the current thread

    Synchronous dispatch to parallel queues: no new threads are started, tasks are executed in sequence, blocking the current thread

    Asynchronous dispatch to the serial queue: start a new thread (one), tasks are executed in sequence, without blocking the current thread

    Asynchronously dispatched to parallel queues: Do not start new threads (multiple, the specific number is determined by the current system), tasks are executed in parallel, and the current thread is not blocked

4. Main Queue

    Main Dispatch Queue : The main queue, a special serial queue, the processing appended to the main queue is executed in the Runloop of the main thread.

     Synchronous dispatch to the main queue: the current thread is the main thread, which will cause a deadlock. The current thread is a non-main thread, and no new threads are opened. The tasks are executed in order, blocking the current thread.

     Asynchronous dispatch to the main queue: no new threads are started, tasks are executed in sequence, and the current thread is not blocked

    

    



    

    

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324474242&siteId=291194637
gcd