Gcd multithreading tips in iOS development

Source: Internet
Author: User

Gcd multithreading tips in iOS development

This article will be updated continuously:

We often use:
 
Dispatch_async (dispatch_get_global_queue (0, 0), ^ {// code block for processing time-consuming operations // notify the main thread to refresh dispatch_async (dispatch_get_main_queue (), ^ {// callback or notify the main thread to refresh });});

Among them, main_queue is the system's default serial queue and global_queue is the system's default parallel queue.

What is a Serial Queue (Serial )?

Create any number of serial queues. Each queue executes the added tasks in sequence. Only one task (Serial) can be executed in one queue at a time. However, the tasks can be executed concurrently without affecting each queue. Tasks in each queue run on an independent thread maintained by their respective serial queues. Each queue has only one thread.

What is Concurrent )?

Parallel queues cannot be created by yourself. There are three parallel Queues with different priorities in the system. The parallel queue still starts the task according to the task addition sequence. However, the latter task does not need to wait until the previous task is completed. Instead, it starts the first task and starts the next task immediately. The number of tasks that can be run at the same time is systematically determined. Each task runs on an independent thread provided by the parallel queue. How many threads must be maintained when multiple tasks run in the parallel queue at the same time.

Another concept in gcd is the master scheduling queue.

The tasks in the main scheduling queue run on the main thread of the application. Therefore, if you want to modify the application interface, it is the only choice.

As follows:

 
Dispatch_async (dispatch_get_main_queue (), ^ {// operations with the New Territories });

Run only once:
 
Static dispatch_once_t onceToken; dispatch_once (& onceToken, ^ {// The code written here will only be executed once });

If you have collected useful usage information about gcd, please share it with me and comment directly below the article.

My public account:

 
iOSDevTip

 

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.