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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to