Grand Central Dispatch: The Sleeping Barber Problem
madebysofa.com
madebysofa.com
You can fix this by using dispatch_group_async instead of dispatch_async, then after the loop (before releasing the queue) call dispatch_group_wait to make sure all the queued blocks have completed.
This plus creating and releasing the group only adds three lines of code; the rest of the author's algorithm is correct as far I can tell.
I guess it just goes to show that even with Grand Central you still have to be a little careful.
The sample code is technically correct, but your argument is also valid. I was going for a demo of something that applies in the larger scope of real-world apps :)
GCD, by no stretch of the imagination, negates the requirement of thought!
The thing is, Objective C is the main way to develop Cocoa applications. Blocks, garbage collection, and a number of other features that have been roundly whined about are ways of increasing the expressivity of the language so that it is more comfortable to write applications in. One can argue that C is a miserable applications development language (and I think you'd be right) but unfortunately we have relatively few other options. Apple used to have a Java-Cocoa bridge that has been deprecated for some time because nobody cared.
Blocks in C have lead to a great simplification of my own code. A lot less jumping from method to method. There is no way that these are a bad thing.