by vilya · 17y ago · 0 comments
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!