• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
multiple NSManagedObjectContexts and single NSPersistentStoreCoordinator
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

multiple NSManagedObjectContexts and single NSPersistentStoreCoordinator


  • Subject: multiple NSManagedObjectContexts and single NSPersistentStoreCoordinator
  • From: "Justin R. Miller" <email@hidden>
  • Date: Sun, 28 Jan 2007 16:45:56 -0500

I have researched this in the list archives and believe I'm taking the proper approach, but have a clarification question.

I need to access my Core Data store in a background thread. Thus, the thread has its own managed object context to avoid having to lock the main UI thread's context.

I am sharing the same persistent store coordinator between these two contexts without any locking. This seems kosher according to Apple's documentation here:

http://developer.apple.com/documentation/Cocoa/Conceptual/CoreData/ Articles/cdMultiThreading.html#//apple_ref/doc/uid/TP40003385

You can use one persistent store coordinator per group of cooperating threads (for example, for your application or for each document).

However, a bit further down is what seems like a contradiction to me:

If you do share a managed object context or a persistent store coordinator between threads, and you invoke any methods on it, you need to ensure that they are invoked from a thread-safe scope. Typically this means you must lock the context or coordinator using tryLock or lock. If you do this, the framework will ensure that what it does behind the scenes is also thread-safe. For example, if you create one context per thread, but all pointing to the same persistent store coordinator, Core Data takes care of accessing the coordinator in a thread-safe way ...

Is this only referring to accessing the coordinator directly across threads (i.e. not when accessing it via a context)? Or in general?


Am I doing things safely here?

--
Justin R. Miller
Code Sorcery Workshop
http://codesorcery.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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


  • Prev by Date: NSButton Text Color?
  • Next by Date: Re: custom NSPopupButton
  • Previous by thread: Re: NSButton Text Color?
  • Next by thread: Re: Flipping Text
  • Index(es):
    • Date
    • Thread