What's the best way to set up concurrent execution of for loops in Objective C?
问题 I have a situation with a time-intensive for loop like this: int sum = 0; for (int i = 0; i < max; ++i) sum += dosomething(i); The do something(i) calls are independent. This cries out for multithreading. Using NSOperationQueue on a two-core machine, I can do this: int __block midpoint; int __block sum1; int __block sum2; midpoint = max/2; sum1 = 0; sum2 = 0; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; NSOperation *operation = [NSBlockOperation blockOperationWithBlock: ^{ for