Re: NSXMLParser thread safe?
Re: NSXMLParser thread safe?
- Subject: Re: NSXMLParser thread safe?
- From: Graham Cox <email@hidden>
- Date: Sat, 02 Jun 2012 12:58:14 +1000
On 02/06/2012, at 11:15 AM, Kyle Sluder wrote:
> 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.
Right, thanks for the clarification.
In this case, it's not the same NSXMLParser instance - it's a new instance for each file I need to parse.
I found the source of my crashes - I was sharing an NSTextLayout object among the different objects used to layout text. Previously that worked on the main thread because only one was in use at a time, but it's not thread-safe. Making a new instance each time fixed that problem.
A similar issue concerned the use of [NSFileManager sharedManager] - making that a new instance instead allowed access from several threads (I believe this particular case is documented).
There are still some shared objects, such as the NSFontManager, but that hasn't caused any problems so far.
--Graham
_______________________________________________
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