Re: NSOperation and threadDictionary
Re: NSOperation and threadDictionary
- Subject: Re: NSOperation and threadDictionary
- From: Rick Mann <email@hidden>
- Date: Wed, 22 Sep 2010 11:31:38 -0700
On Sep 22, 2010, at 11:17:25, Julien Poissonnier wrote:
>
> On Sep 22, 2010, at 12:52 AM, Rick Mann wrote:
>
>> Does iOS (and Mac OS X) clean up thread-local storage upon the completion of an NSOperation? It seems dangerous to rely on every operation to clean up its own mess. It also seems that an NSOperation should be able to pretend that it owns the thread on which it's running, and not have to worry about whatever a previous operation running on that thread might've done to the TLS.
>>
>> I read the NSOperation and NSOperationQueue docs, as well as the docs for -[NSThread threadDictionary], but none of it mentions this topic.
>>
>> I can experiment to find out, but would like to know what others know about this.
>>
>> Thanks,
>> Rick
>>
>
> I don't know what happens to the threadDictionary when an NSOperationQueue "recycles" a thread, but the Concurrency Programming Guide states that you should avoid per-thread storage and consider the thread owned by the NSOperationQueue, not the NSOperation:
> http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationObjects/OperationObjects.html#//apple_ref/doc/uid/TP40008091-CH101-SW27
Thanks, Julien. I hadn't seen that.
Pity. We have a singleton object that creates a subclass of NSOperation, which then calls back a method on the singleton that's intended to be run on a separate thread (provided indirectly by the NSOperation). That singleton needs it's own NSManagedObjectContext, which we were creating and then passing around to everything the singleton called. We wanted to avoid the danger of creating additional ones by storing it in TLS, but I guess we're not supposed to do that (although it does talk about data that you "create yourself or manage," which is the case here).
Thanks, I'll modify what we're doing.
--
Rick
_______________________________________________
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