iOS GCD Simple Introduction

Source: Internet
Author: User

This from the practice of simple explanation:

First, GCD is the acronym for the Grand Central Dispatch, meaning multithreading optimization technology, which is optimized for multi-core processing by Apple. Easy to use and clear.

Multithreading is divided into synchronous, asynchronous methods as follows:

// Asynchronous Thread Open: dispatch_async (dispatch_queue_t queue, ^ (void) block)// sync thread on: Dispatch_sync (dispatch_queue_t queue, ^ (void//dispatch_queue_t: Queue block: Execution content

Description of the queue:

The creation method is as follows:

Dispatch_queue_create (constchar *label, dispatch_queue_attr_t attr)

Parameter description: Label for queue name attr as queue serial: Dispatch_queue_serial parallel: dispatch_queue_concurrent

Special Queue Description:

The system defaults to a serial queue main_queue and parallel queue Global_queue using the following methods:

Dispatch_get_main_queue ()// home row dispatch_get_global_queue (longlong  flags) ; /* Identifler: Priority *  -Dispatch_queue_priority_high:    2     *  -Dispatch_queue_priority_default:      0 *  -dispatch_queue_priority_low:      -2 *  */

Finally, special threads:

 //The thread after which the previous thread ends after executing this thread ends before executing itDispatch_barrier_async (dispatch_queue_t queue, ^ (void) block) Dispatch_barrier_sync (dispatch_queue_t queue,^(void) block)//number of thread iterations repeatedly executedDispatch_apply (size_t iterations, dispatch_queue_t queue, ^(size_t) block)//Execute only onceStaticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{          //code to be executed once    }); //Deferred execution nsec_per_sec secdispatch_time_t poptime = Dispatch_time (Dispatch_time_now, Delayinseconds *nsec_per_sec); Dispatch_after (Poptime, Dispatch_get_main_queue (),^(void){          //Code to is executed on the main queue after delay    }); //set the priority of a dispatch queuevoidDispatch_set_target_queue (dispatch_object_tObject, dispatch_queue_t queue)

iOS GCD Simple Introduction

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.