The principle of multi-threaded CGD dispatching group

Source: Internet
Author: User
Tags gcd

Our common GCD scheduling group approach

1 //gcd Common Dispatching group2-(void) demo1{3     4     //create dispatch groups and queues5dispatch_group_t Group =dispatch_group_create ();6dispatch_queue_t queue = Dispatch_queue_create ("Changyong", dispatch_queue_concurrent);7     8     //to add a task to a dispatch group9Dispatch_group_async (group, queue, ^{TenNSLog (@"time-consuming operation _11111111"); One     }); ADispatch_group_async (group, queue, ^{ -         //simulate time-consuming operations -[Nsthread Sleepfortimeinterval:2]; theNSLog (@"time-consuming operation _22222222"); -     }); -Dispatch_group_async (group, queue, ^{ -NSLog (@"time-consuming operation _33333333"); +     }); -      +     //tasks performed after all tasks have been completed ADispatch_group_notify (Group, Dispatch_get_main_queue (), ^{ atNSLog (@"All tasks complete, update UI actions"); -     }); -}

GCD Scheduling Group principle

1 //principle and method of GCD dispatching group2-(void) demo2{3     4     //create dispatch groups and queues5dispatch_group_t Group =dispatch_group_create ();6dispatch_queue_t queue = Dispatch_queue_create ("Yuanli", dispatch_queue_concurrent);7     8     //Task 19 Dispatch_group_enter (group);TenDispatch_async (Queue, ^{ OneNSLog (@"Task 1"); A Dispatch_group_leave (group); -     }); -      the     //Task 2 - Dispatch_group_enter (group); -Dispatch_async (Queue, ^{ -[Nsthread Sleepfortimeinterval:2]; +NSLog (@"Task 2"); - Dispatch_group_leave (group); +     }); A      at     //Task 3 - Dispatch_group_enter (group); -Dispatch_async (Queue, ^{ -NSLog (@"Task 3"); - Dispatch_group_leave (group); -     }); in      -     //All Tasks completed toDispatch_group_notify (Group, Dispatch_get_main_queue (), ^{ +         -NSLog (@"The task finishes, refreshes the UI"); the     }); *      $     //wait for the above code to execute after executing the following code, Parameter 2: Wait Time outPanax Notoginseng     //dispatch_group_wait (Group, dispatch_time_forever); -      theNSLog (@"Hello"); +}

The principle of multi-threaded CGD dispatching group

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.