Multi-threaded----Dispatch Group Technology dispatch_group_t

Source: Internet
Author: User

A dispatch group allows an organization thread to know that one or more tasks are completed.

If you have a scenario where the main thread should not continue to run until the task in the queue is finished, you can use dispatch group technology to have one or more queues wait for the execution to complete before returning to the main thread.

The following example shows the basic usage of creating a dispatch group:

dispatch_queue_t queue = Dispatch_get_global_queue (Dispatch_queue_priority_default, 0);        dispatch_group_t group = Dispatch_group_create ();        Dispatch_group_async (group, queue, ^{//perform some asynchronous work}); Some other processing//waits in the dispatch group, preventing the current thread from continuing to execute dispatch_group_wait (group, dispatch_time_forever);

adding queues and tasks to a group, using method Dispatch_group_async, line 11th calls the Dispatch_group_wait method to wait until the task in all groups is finished before it returns.


------------from iOS app development best Practices


Multi-threaded----Dispatch Group Technology dispatch_group_t

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.