IOS Multithreaded Learning Note--GCD

Source: Internet
Author: User
Tags gcd

This article copies, references from the article: iOS multithreaded Programming Grand Central Dispatch (GCD) introduced and used, mainly in order to strengthen the understanding of the knowledge and memory of the individual, do not do his use. Original Author statement:

Copyright statement: This article by http://blog.csdn.net/totogo2010/Original, welcome reprint share. Please respect the author Labor, reproduced when the statement and the author of the blog link, thank you!

Thanks for the hard work of the original author here!

1. Introduction

The GCD (Grand Central Dispatch) is built on the thread pool pattern of parallel execution of tasks to optimize support for multi-core, multiprocessor systems.

GCD works by allowing programs to queue in parallel to specific tasks, scheduling them to perform tasks on any available core, depending on the available processing resources. A task can be a function or a block.

The bottom of the GCD is still threaded, but it doesn't have to be concerned with implementation details.

The FIFO queue of the GCD is called the Dispatch queue (dispatch), which guarantees first-come execution first. Dispatch, the queue is divided into the following 3 kinds:

(1) Serial (continuous)

Also known as the private dispatch queue (Pirvate-Dispatch queue), while performing only one task. Serial queues are typically used to synchronize access to specific resources or data. When more than one serial queue is created, the queues are executed concurrently, although they are executed separately within their respective queues.

(2) Concurrent (concurrent)

Also known as the global dispatch queue, multiple tasks in the queue can be executed concurrently, but the order in which the execution is completed is random.

(3) Main dispatch queue

It is a globally available serial queue that performs tasks on the main thread of the application.

2. Use of scheduling queues

2.1 Common methods of Dispatch_async

To prevent the interface from being stuck in processing time-consuming operations, such as reading network data, IO, database reading and writing, we will process these operations in another thread and then notify the main thread to update the interface.

Using GCD to implement this process is simpler than the Nsthread\nsoperation method described previously, and the code is as follows:

0), ^{        //  Time-consuming operation    ^{       //  Update interface   });});

Example:

IOS Multithreaded Learning Note--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.