Re: Surprising entanglement of UI lock during fetch request in background thread (NSViewHierarchyLock/MOC locking deadlock).
Re: Surprising entanglement of UI lock during fetch request in background thread (NSViewHierarchyLock/MOC locking deadlock).
- Subject: Re: Surprising entanglement of UI lock during fetch request in background thread (NSViewHierarchyLock/MOC locking deadlock).
- From: Chris Hanson <email@hidden>
- Date: Sat, 21 Feb 2009 11:39:02 -0800
On Feb 20, 2009, at 11:57 AM, Luke Evans wrote:
My app has a table whose content shows files. The files that get
shown here are stored in Core Data, the table is bound to the Core
Data model to show the appropriate stuff.
A background thread is started to spider through the file system
looking for appropriate files. When a new candidate file is
spotted, the managed object context is locked, and the file is added
to the 'store'.
This is the problem. Bindings are not thread-safe. That is, bindings
don't take a lock before access. Thus even though your code is
locking the managed object context that is shared between the threads,
AppKit isn't, and therefore you'll run into all sorts of consistency
issues.
You should probably pursue a context-per-thread approach for this kind
of use, where the contexts share a persistent store coordinator. Then
when your background thread wants to tell the main thread about
something, it can just pass it an object ID that the main thread can
use to get the object in its own context.
-- Chris
_______________________________________________
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