dispatch_async and [NSURLConnection sendSynchronousRequest]

Viewed 1958

There are various questions around this topic, and lots of advice saying NOT to use sendSynchronousRequest within dispatch_async, because it blocks the thread, and GCD will spawn lots of new worker threads to service all the synchronous URL requests.

Nobody seems to have a definitive answer as to what iOS 5, [NSURLConnection sendAsynchronousRequest:queue:completionHandler:] does behind the scenes.

One post I read states that it 'might' optimise, and it 'might' use the run loop - but certainly won't create a new thread for each request.

When I pause my debugger when using sendAsynchronousRequest:queue:completionHandler, the stack trace looks like this:

screenshot

..now it appears that sendAsynchronousRequest:queue:completionHandler, is actually calling sendSynchronousRequest, and I still have tons of threads created when I use the async method instead of the sync method.

Yes, there are other benefits to using the async call, which I don't want to discuss in this post.

All I'm interested in is performance / thread / system usage, and if i'm worse off using the sync call inside dispatch_async instead of using the async call.

I don't need advice on using ios4 async calls either, this is purely for educational purposes.

Does anyone have any insightful answers to this?

Thanks

2 Answers
Related