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