• 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: Modifying outside properties from NSOperation subclass
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modifying outside properties from NSOperation subclass


  • Subject: Re: Modifying outside properties from NSOperation subclass
  • From: Nick Zitzmann <email@hidden>
  • Date: Mon, 14 Dec 2009 21:09:31 -0700

On Dec 14, 2009, at 9:07 PM, PCWiz wrote:

> So to make it clear, I invoke the method as an NSInvocationOperation then in the method I do this whenever I need to access the mutable dictionary:
>
> - (void)doResourceHungryTask {
> 	...
> 	@synchronized (myDictionary) {
> 		[myDictionary setObject:anObject forKey:@"testKey"];
> 	}
> }
>
> Is that correct?

You must lock and unlock the dictionary **every** time you read from or write to it, not just that one time. Otherwise one thread could access it at the same time as another thread is writing to it, and that would not be good.

Nick Zitzmann
<http://www.chronosnet.com/>



_______________________________________________

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: Modifying outside properties from NSOperation subclass
      • From: PCWiz <email@hidden>
References: 
 >Modifying outside properties from NSOperation subclass (From: PCWiz <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: Nick Zitzmann <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: PCWiz <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: Nick Zitzmann <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: PCWiz <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: Nick Zitzmann <email@hidden>)
 >Re: Modifying outside properties from NSOperation subclass (From: PCWiz <email@hidden>)

  • Prev by Date: Re: Modifying outside properties from NSOperation subclass
  • Next by Date: Re: Modifying outside properties from NSOperation subclass
  • Previous by thread: Re: Modifying outside properties from NSOperation subclass
  • Next by thread: Re: Modifying outside properties from NSOperation subclass
  • Index(es):
    • Date
    • Thread