Multi-Threading implementation in iOS _05_GCD

Source: Internet
Author: User
Tags gcd

First, basic concept 1, what is GCD
    • The full name is Grand Central Dispatch, which translates as "the backbone scheduler"
    • Pure C Language , provides a lot of powerful functions
2, the advantages of GCD
    • GCD is Apple's solution for multi-core parallel computing
    • GCD will automatically take advantage of more CPU cores (such as dual-core, quad-core)
    • GCD automatically manages the life cycle of threads (create threads, schedule tasks, destroy threads)
    • Programmers just need to tell gcd what tasks they want to perform, without having to write any thread management code
3. Tasks and Queues

(1) There are 2 core concepts in GCD

Task: what action to take

Queues: Used to store tasks

(2) The use of GCD is 2 steps

customizing tasks

Identify the things you want to do

(3) Adding tasks to the queue

  GCD will automatically take the tasks in the queue and put them in the corresponding thread.

The removal of a task follows the FIFO principle of the queue: first-in, LIFO, and post-

II. implementation of Task 1, implementation of tasks

(1) There are 2 functions used to perform the task in GCD

Perform tasks in a synchronized manner

Dispatch_sync(dispatch_queue_t queue, dispatch_block_t block);

Queue: Queues

Block: Task

Perform a task in an asynchronous manner

Dispatch_Async(dispatch_queue_t queue, dispatch_block_t block);

(2) The difference between synchronous and asynchronous

  synchronization : Executing in the current thread

  Async : Executing in another thread

2. Type of queue

The GCD queue can be divided into 2 major types

(1) concurrent queues (Concurrent Dispatch queue)

Multiple tasks can be executed concurrently (concurrently) (automatic opening of multiple threads concurrently executing tasks)

  concurrency function is only valid under asynchronous (Dispatch_async) functions

(2) serial queuing (Serial Dispatch queue)

Let the task execute one after the other (once a task has finished executing, then the next task is performed)

3, more easily confused terminology: synchronous, asynchronous, concurrent, serial

(1) Synchronous and asynchronous determine whether to open a new thread

Synchronous: Performs a task in the current thread without the ability to open a new thread

Async: Perform a task in a new thread with the ability to open a new thread

(2) Concurrency and serial determine how tasks are executed

Concurrency: Multiple tasks concurrently (concurrently) executed

Serial: Once a task is completed, the next task is performed

Iii. Creating queue 1, concurrent (parallel) queues

Multi-Threading implementation in iOS _05_GCD

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.