Re: Handling NSManagedObjectContextDidSaveNotification from different threads
Re: Handling NSManagedObjectContextDidSaveNotification from different threads
- Subject: Re: Handling NSManagedObjectContextDidSaveNotification from different threads
- From: Rick Mann <email@hidden>
- Date: Wed, 11 Aug 2010 13:07:03 -0700
On Aug 11, 2010, at 12:55:26, Keary Suska wrote:
> On Aug 10, 2010, at 2:55 PM, Rick Mann wrote:
>
>> We have an app that uses a "main" NSManagedObjectContext (MOC) for all UI-related work, and has background threads that add and update data via their own dedicated MOCs. When they call -save: on their MOC, the "main" MOC gets the NSManagedObjectContextDidSaveNotification and calls -mergeChangesFromContextDidSaveNotification:.
>>
>> The problem is, this actually happens on the thread that called -save:, not on the main thread. We're seeing occasional crashes, and suspect that it is due to this problem. However, I didn't see anything in the docs that said we had to call -save: from the main thread, or take any special steps when handling that notification.
>>
>> Did I just overlook something, or should this work safely always? It seems like the latter is unlikely, since two threads could be accessing a MOC simultaneously.
>
> Are you following or taking into account everything shown here: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CoreData/Articles/cdMultiThreading.html#//apple_ref/doc/uid/TP40003385-SW1 ?
We did, as far as anyone here knows. I just find it interesting that the preferred approach, to use multiple MOCs and one PSC, creates a situation in which a MOC is likely to be manipulated by multiple threads: when handling the didSave notification.
>
> Keary Suska
> Esoteritech, Inc.
> "Demystifying technology for your home or business"
>
_______________________________________________
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