Re: index beyond bounds when using a queue for a for-loop
Re: index beyond bounds when using a queue for a for-loop
- Subject: Re: index beyond bounds when using a queue for a for-loop
- From: Jens Alfke <email@hidden>
- Date: Mon, 12 Aug 2013 11:05:30 -0700
On Aug 12, 2013, at 10:36 AM, Koen van der Drift <email@hidden> wrote:
> dispatch_apply(count, queue, ^(size_t i)
> {
> myArray[i] = [self doCalculation: i];
> });
NSMutableArray isn’t thread-safe. You’ll need to synchronize/serialize the assignments somehow. You could do something like
{
id value = [self doCalculation: i];
@synchronized(myArray) {
myArray[i] = value;
}
}
although there is probably some nicer GCD API to do the same thing.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden