IOS GCD Common

Source: Internet
Author: User

The dispatch queue is divided into the following three types:

1) Run the main queue in the main thread, obtained through Dispatch_get_main_queue.

2) Parallel queue Global dispatch queue, obtained by Dispatch_get_global_queue, creates three different priority dispatch queues by the system. Parallel queues are executed in the same order as they join the queue.

3) Serial queue serial queues is typically used to synchronize access sequentially, creating any number of serial queues that are concurrent between each serial queue.

Background execution: Dispatch_async (dispatch_get_global_queue (0, 0), ^{//Something}); Main thread execution: Dispatch_async (Dispatch_get_main_queue (), ^{//Something}); Disposable execution: Static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{//code to be executed once}); Delay 2 seconds execution: double delayinseconds = 2.0; dispatch_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}); Custom dispatch_queue_t dispatch_queue_t urls_queue = dispatch_queue_create ("blog.devtang.com", NULL); Dispatch_async (Urls_queue, ^{//Your code}); Dispatch_release (Urls_queue); Merge Summary results dispatch_group_t group = dispatch_group_create (); Dispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{//parallel execution of thread one}); Dispatch_group_async (Group, Dispatch_get_global_queue (0,0), ^{//Parallel execution thread two}); Dispatch_group_notify (Group, Dispatch_get_global_queue (0,0), ^{      Aggregated results}); 




IOS GCD Common

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.