• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: index beyond bounds when using a queue for a for-loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: index beyond bounds when using a queue for a for-loop
      • From: Koen van der Drift <email@hidden>
References: 
 >index beyond bounds when using a queue for a for-loop (From: Koen van der Drift <email@hidden>)

  • Prev by Date: index beyond bounds when using a queue for a for-loop
  • Next by Date: Re: index beyond bounds when using a queue for a for-loop
  • Previous by thread: index beyond bounds when using a queue for a for-loop
  • Next by thread: Re: index beyond bounds when using a queue for a for-loop
  • Index(es):
    • Date
    • Thread