Reputation: 51
I am trying to parallel a simple for loop with pthread. All it needs to do is to access a global array by different thread.
for(int i = 0, i < ary.count; i++){
//do something with ary[i];
}
How to do that?
Upvotes: 0
Views: 252
Reputation: 318944
You can use NSArray enumerateObjectsWithOptions:usingBlock:
to enumerate the elements of the array using multiple threads:
[ary enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id object, NSUInteger index, BOOL *stop) {
// do something with object
}];
Upvotes: 1