Re: NSXMLParser thread safe?
Re: NSXMLParser thread safe?
- Subject: Re: NSXMLParser thread safe?
- From: Kyle Sluder <email@hidden>
- Date: Fri, 01 Jun 2012 18:15:09 -0700
On Jun 1, 2012, at 4:18 PM, Graham Cox <email@hidden> wrote:
>
> On 02/06/2012, at 1:55 AM, Nick Zitzmann wrote:
>
>> That depends. How are you creating the thread? It isn't difficult to do using either the pthread or NSThread APIs.
>
>
> Well, I started with the NSThread method that I've used classically, but moved it over to using NSInvocationOperations in a NSOperationQueue. This second approach is easier, and more stable, but I found a few places where things were going pear shaped, mostly to do with accessing shared caches, which was easily dealt with using @synchronised blocks.
It's important to note that operation queues (and dispatch queues for that matter) do not guarantee anything about what threads your operations execute on. Apple's notoriously slippery definition of "thread-safe" can still bite you if the implication is that an NSXMLParser instance is safe to use from a non-main thread as long as *all* uses are from the *same* thread. That would make it unsafe to access the same NSXMLParser instance from two different NSOperations.
--Kyle Sluder
_______________________________________________
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