Re: Modifying outside properties from NSOperation subclass
Re: Modifying outside properties from NSOperation subclass
- Subject: Re: Modifying outside properties from NSOperation subclass
- From: PCWiz <email@hidden>
- Date: Mon, 14 Dec 2009 21:07:12 -0700
Ok, I think I understand this after reading this document:
http://developer.apple.com/mac/articles/cocoa/managingconcurrency.html
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?
On 2009-12-14, at 9:03 PM, Nick Zitzmann wrote:
>
> On Dec 14, 2009, at 8:59 PM, PCWiz wrote:
>
>> "doResourceHungryTask" would be a method in my delegate class. Would I still need to lock/unlock (I'm modifying the class's properties from itself, not another class)? I'm not sure on the exact workings of NSInvocationOperation, I just found out about it.
>
> Yes, because any operation you enqueue is going to run in a background thread, and NSMutableDictionary is not thread-safe.
>
> 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