Convert an asynchronous thread to a synchronous thread with the GCD thread group and the GCD semaphore

Source: Internet
Author: User
Tags gcd

Convert an asynchronous thread to a synchronous thread with the GCD thread group and the GCD semaphore

Sometimes we come across a situation like this:

At the same time get data of two network requests, but the network request is asynchronous, we need to get to two network request data before we can do the next operation, this time, is the thread group and the signal volume of the use.

A thread group listens to the execution of threads, and semaphores are used to convert an asynchronous thread into a synchronous thread.

The following is the printed data:

2015-02-25 18:34:23.208 yxmweather[265:8748] request 1 data

2015-02-25 18:34:23.209 yxmweather[265:8790] 1 semaphore end

2015-02-25 18:34:23.927 yxmweather[265:8748] request 2 data

2015-02-25 18:34:23.927 yxmweather[265:8787] 2 semaphore end

2015-02-25 18:34:23.928 yxmweather[265:8748] completed

Convert an asynchronous thread to a synchronous thread with the GCD thread group and the GCD semaphore

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.